iOS仿简书、淘宝等App的View弹出效果

2020-01-15 19:00:09于丽

然后关键的layer形变方法来了


- (CATransform3D)firstTransform{
 CATransform3D t1 = CATransform3DIdentity;
 t1.m34 = 1.0/-900;
 //带点缩小的效果
 t1 = CATransform3DScale(t1, 0.95, 0.95, 1);
 //绕x轴旋转
 t1 = CATransform3DRotate(t1, 15.0 * M_PI/180.0, 1, 0, 0);
 return t1;

}

- (CATransform3D)secondTransform{

 CATransform3D t2 = CATransform3DIdentity;
 t2.m34 = [self firstTransform].m34;
 //向上移
 t2 = CATransform3DTranslate(t2, 0, self.view.frame.size.height * (-0.08), 0);
 //第二次缩小
 t2 = CATransform3DScale(t2, 0.8, 0.8, 1);
 return t2;
}

 

大家可以看到这,应该可以发现这里其实有两次形变

3.隐藏动画


- (void)close
{
 _isShow = NO;
 
 CGRect frame = _popView.frame;
 frame.origin.y += self.view.frame.size.height/2.0;
 
 [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
 
  //maskView隐藏
  [_maskView setAlpha:0.f];
  //popView下降
  _popView.frame = frame;
  //同时进行 感觉更丝滑
  [_rootview.layer setTransform:[self firstTransform]];
 
 } completion:^(BOOL finished) {
 
  [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
   //变为初始值
   [_rootview.layer setTransform:CATransform3DIdentity];
 
  } completion:^(BOOL finished) {
 
   //移除
    [_popView removeFromSuperview];
  }];
 
 }];
 
 
}

最后,完整代码,已经封装好了,继承之后使用创建方法就行了

GitHub:Wzxhaha

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到IOS开发频道。