美文网首页ios新知识
IOS开动画效果之──实现 pushViewController

IOS开动画效果之──实现 pushViewController

作者: Ray_win | 来源:发表于2015-06-06 11:00 被阅读4239次

 在开发中,视图切换会常常遇到,有时我们不是基于导航控制器的切换,但实际开发中,有时需要做成push效果,下面将如何实现push和pop 默认动画效果代码实例:

一、push默认动画效果

CATransition *transition = [CATransition animation];

transition.duration = 0.3f;

transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionPush;

transition.subtype = kCATransitionFromRight;

transition.delegate = self;

[self.contentView.layer addAnimation:transition forKey:nil];

[self.contentView addSubview:self.productDetailController.view];

注:self.contentView是工程中的UIView,self.productDetailController是工程中的controller

        只需要把两者替换成合适的内容即可用

  二、pop默认动画效果

CATransition *transition = [CATransition animation];

transition.duration = 0.3f;

transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionPush;

transition.subtype = kCATransitionFromLeft;

transition.delegate = self;

[self.view.superview.layer addAnimation:transition forKey:nil];

[self.view removeFromSuperview];

 说明:.type 设置了主要的页面切换显示形式

           .subtype 设置了页面的旋转  左右上下

相关文章

网友评论

  • 贪吃鱼:请问代码实现到哪个代码中啊'有例子么

本文标题:IOS开动画效果之──实现 pushViewController

本文链接:https://www.haomeiwen.com/subject/xugdqttx.html