现在的位置: 首页 > 综合 > 正文

ios视图缩放动画

2018年05月06日 ⁄ 综合 ⁄ 共 960字 ⁄ 字号 评论关闭

效果:视图从大--小缩放显示/小--大 (只是比例问题)
方法1.直接show出view的时候:
把下面的这段代码加到viewController或者view出现的时候就OK

self.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);//将要显示的view按照正常比例显示出来
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //InOut 表示进入和出去时都启动动画
[UIView setAnimationDuration:0.5f];//动画时间
self.view.transform=CGAffineTransformMakeScale(0.01f, 0.01f);//先让要显示的view最小直至消失
[UIView commitAnimations]; //启动动画
//相反如果想要从小到大的显示效果,则将比例调换
//UIGraphicsGetCurrentContext 里面东西很丰富。
——————————————————————————————————————————
方法2.push一个viewController时:
把下面的代码加到push的方法里面就OK
CATransition *myTranstiton = [CATransition animation];
myTranstiton.duration = 0.5;
myTranstiton.type = kCATransitionFade; 
//myTranstiton.subtype = kCATransitionFromTop; 
[self.view.superview.layer addAnimation:myTranstiton forKey:nil ]; 
MainViewController * _mainViewController=[[MainViewController alloc] init];
[self presentModalViewController:_mainViewController animated:NO];  

抱歉!评论已关闭.