IOS中我们可以通过Storyborad以及segue来实现我们自己的场景切换动画,新建项目使用Single View Application模板并取名为MyCustomSegue。
使用storyboard托出另一UIViewController并分设置两个控制器的视图颜色,并设置跳转页面的segue为custom
设置如图
新建文件MyCustomChangeSegue并重新perform方法
@implementation MyCustomChangeSegue -(void)perform
{
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destViewController = self.destinationViewController; [UIView animateWithDuration: animations:^{
CGPoint centerPoint = sourceViewController.view.center;
sourceViewController.view.frame = CGRectMake(centerPoint.x,centerPoint.y , , );
sourceViewController.view.alpha = ;
} completion:^(BOOL success){
UIView *destView = destViewController.view;
sourceViewController.view.hidden = YES;
[[sourceViewController.view superview] addSubview:destView];
CGRect destRect = destView.frame;
CGPoint centerPoint = destView.center;
destView.frame = CGRectMake(centerPoint.x,centerPoint.y , , );
destView.alpha = ;
[UIView animateWithDuration:0.3 animations:^{
destView.frame = destRect;
destView.alpha = ;
} completion:^(BOOL success){
destView.alpha = ;
destView.frame = destRect;
sourceViewController.view.hidden = NO;
[sourceViewController presentViewController:destViewController animated:NO completion:nil];
}];
}];
} @end
运行程序点击go按钮,我们就会看到神奇的一幕了!