iOS开发--不使用UINavigationController实现Push动画
2015-02-27 11:13
323 查看
在iOS开发中,如果使用UINavigationController,配合Storyboard+Push模式的Segue,默认情况下,可以直接实现左右推出的View切换效果。
但是,如果不使用UINavigationController时,把Segue设置为Push,运行就会直接报错,而Model模式的Segue只有Cover Vertical,Flip Horizontal,Cross Dissolve和Partial Curl这4种模式,没有Push模式。
如果要在自定义的View切换动画中使用Push模式,唯一的方法是把Segue设置为Custom,然后自定义Push动画。
自定义View切换动画效果的实现方式是从UIStoryboardSegue派生一个类,然后在
经过多次Google,找到多种实现方式,经比较后发现,最简单最靠谱的Push动画实现如下:
将旧的View向左移动,新的View从最右开始进入。
最后,在动画结束后,手动将当前View切换到新的View:
因为动画效果我们已经自己实现了,所以切换到新的View就不要使用动画了。
简单修改上面的代码,就可以实现从左到右的Push切换动画:
利用Custom模式的Segue,可以实现任意切换动画效果,对于简单的非3D动画,简单的几行代码即可实现。
实例教程:http://www.cocoachina.com/ios/20150126/11011.html
但是,如果不使用UINavigationController时,把Segue设置为Push,运行就会直接报错,而Model模式的Segue只有Cover Vertical,Flip Horizontal,Cross Dissolve和Partial Curl这4种模式,没有Push模式。
如果要在自定义的View切换动画中使用Push模式,唯一的方法是把Segue设置为Custom,然后自定义Push动画。
自定义View切换动画效果的实现方式是从UIStoryboardSegue派生一个类,然后在
-(void)perform方法中自己实现动画。
经过多次Google,找到多种实现方式,经比较后发现,最简单最靠谱的Push动画实现如下:
- (void)perform { UIViewController* source = (UIViewController *)self.sourceViewController; UIViewController* destination = (UIViewController *)self.destinationViewController; CGRect sourceFrame = source.view.frame; sourceFrame.origin.x = -sourceFrame.size.width; CGRect destFrame = destination.view.frame; destFrame.origin.x = destination.view.frame.size.width; destination.view.frame = destFrame; destFrame.origin.x = 0; [source.view.superview addSubview:destination.view]; [UIView animateWithDuration:.25 animations:^{ source.view.frame = sourceFrame; destination.view.frame = destFrame; } completion:^(BOOL finished) { [source presentViewController:destination animated:NO completion:nil]; }]; }以上就是从右向左切换View动画的实现,关键代码是:
sourceFrame.origin.x = -sourceFrame.size.width;
destFrame.origin.x = destination.view.frame.size.width;
将旧的View向左移动,新的View从最右开始进入。
最后,在动画结束后,手动将当前View切换到新的View:
[source presentViewController:destination animated:NO completion:nil];
因为动画效果我们已经自己实现了,所以切换到新的View就不要使用动画了。
简单修改上面的代码,就可以实现从左到右的Push切换动画:
CGRect sourceFrame = source.view.frame; sourceFrame.origin.x = sourceFrame.size.width; CGRect destFrame = destination.view.frame; destFrame.origin.x = -destination.view.frame.size.width; destination.view.frame = destFrame;
利用Custom模式的Segue,可以实现任意切换动画效果,对于简单的非3D动画,简单的几行代码即可实现。
实例教程:http://www.cocoachina.com/ios/20150126/11011.html
相关文章推荐
- iOS 不使用UINavigationController实现Push动画
- iOS开发使用sdWebImage实现对tableView的cell加载图片淡入动画
- iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理
- 【iOS-Cocos2d游戏开发之二十二 】CCSpeed实现CCAnimate动画进行时设置慢动作以及设置游戏加减速进行(塔防游戏必备)!
- 【iOS-Cocos2d游戏开发之二十二 】CCSpeed实现CCAnimate动画进行时设置慢动作以及设置游戏加减速进行(塔防游戏必备)!
- Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)
- IOS开发中使用照相机功能的实现
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- 【iOS-Cocos2d游戏开发之二十二 】CCSpeed实现动画进行时慢动作\设置游戏加减速进行
- IOS开动画效果之──实现 pushViewController 默认动画效果
- Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- android游戏开发框架libgdx的使用(二十三)—使用Universal Tween Engine实现动画效果
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- Android游戏开发之使用AnimationDrable实现Frame动画(三十一)
- 【iOS-Cocos2d游戏开发之二十二 】CCSpeed实现CCAnimate动画进行时设置慢动作以及设置游戏加减速进行(塔防游戏必备)! .
- ios开发之UIView动画效果实现二
- IOS开动画效果之──实现 pushViewController 默认动画效果
- 【IOS功能实现】之Core Animation动画开发总结(CALayer)