Xcode 自定义转场动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19243131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode custom segue animation
提问by Jonas Ester
I have a problem with the transition animation between two storyboard controllers. I have a singleView project with two view controllers in the storyboard.
我对两个故事板控制器之间的过渡动画有问题。我在故事板中有一个带有两个视图控制器的 singleView 项目。
Now I wand to make a custom transition animation:
现在我想制作一个自定义的过渡动画:
- my current view controller should disappear to the left
- the new view controller should come from the right
- 我当前的视图控制器应该消失在左边
- 新的视图控制器应该来自右边
I have already a UIStoryboardSegue
class.
我已经有UIStoryboardSegue
课了。
But what should I write in the -(void)perform{}
method??
但是-(void)perform{}
方法里面应该写什么呢??
Thanks a lot,
非常感谢,
Jonas.
乔纳斯。
回答by Odrakir
For that simple segue you can try something like this:
对于那个简单的转场,你可以尝试这样的事情:
- (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:1.0
animations:^{
source.view.frame = sourceFrame;
destination.view.frame = destFrame;
}
completion:^(BOOL finished) {
UIWindow *window = source.view.window;
[window setRootViewController:destination];
}];
}