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按钮,我们就会看到神奇的一幕了!