我对两个故事板控制器之间的过渡动画有疑问。我在情节提要中有一个带有两个视图控制器的 singleView 项目。
现在我想做一个自定义的过渡动画:
- 我当前的视图控制器应该消失在左边
- 新的视图控制器应该来自右边
我已经有一UIStoryboardSegue
堂课了。
但是我应该在-(void)perform{}
方法中写什么?
非常感谢,
乔纳斯。
我对两个故事板控制器之间的过渡动画有疑问。我在情节提要中有一个带有两个视图控制器的 singleView 项目。
现在我想做一个自定义的过渡动画:
我已经有一UIStoryboardSegue
堂课了。
但是我应该在-(void)perform{}
方法中写什么?
非常感谢,
乔纳斯。
对于那个简单的 segue,你可以尝试这样的事情:
- (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];
}];
}