IOS自定义场景切换动画。

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

IOS中我们可以通过Storyborad以及segue来实现我们自己的场景切换动画,新建项目使用Single Viewapplication模板并取名为MyCustomSegue。

使用storyboard托出另一UIViewController并分设置两个控制器的视图颜色,并设置跳转页面的segue为custom

设置如图

新建文件MyCustomChangeSegue并重新perform方法

1@implementationMyCustomChangeSegue23-(void)perform4{5UIViewController *sourceViewController =self.sourceViewController;6UIViewController *destViewController =self.destinationViewController;78[UIView animateWithDuration:1animations:^{9CGPoint centerPoint =sourceViewController.view.center;10sourceViewController.view.frame = CGRectMake(centerPoint.x,centerPoint.y ,0,0);11sourceViewController.view.alpha =0;12} completion:^(BOOL success){13UIView *destView =destViewController.view;14sourceViewController.view.hidden =YES;15[[sourceViewController.view superview] addSubview:destView];16CGRect destRect =destView.frame;17CGPoint centerPoint =destView.center;18destView.frame = CGRectMake(centerPoint.x,centerPoint.y ,0,0);19destView.alpha =0;20[UIView animateWithDuration:0.3animations:^{21destView.frame =destRect;22destView.alpha =1;23} completion:^(BOOL success){24destView.alpha =1;25destView.frame =destRect;26sourceViewController.view.hidden =NO;27[sourceViewControllerPResentViewController:destViewController animated:NO completion:nil];28}];29}];30}3132@end

运行程序点击go按钮,我们就会看到神奇的一幕了!

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航