通过故事板反转自定义 Segue
我有一个自定义的转场动画,当将新的视图控制器推入堆栈时会发生该动画。然而,当弹出带有所述自定义 Segue 的视图控制器时,会发生默认的导航控制器动画(即,当前视图控制器向右移动,而父视图控制器从左边缘在屏幕上平移)。
所以我的问题是:有没有办法编写自定义弹出转场动画,该动画在从堆栈中弹出视图控制器时发生?
编辑(解决方案):
我最终定义了一个与所选答案类似的自定义转场。在 Storyboard 中,我将一个自定义 Segue 从子视图控制器拖回其父视图控制器,为其提供一个标识符和新编写的反向 Segue 作为其类。是的,我意识到它实际上与模式转换相同。客户的要求使得这种疯狂成为必要,所以在任何人发表评论之前,请理解我知道在正常情况下不应该这样做。
- (void)perform {
UIViewController *src = (UIViewController *)self.sourceViewController;
UIViewController *dest = (UIViewController *)self.destinationViewController;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = src.view.frame;
f.origin.y = f.size.height;
src.view.frame = f;
} completion:^(BOOL finished){
src.view.alpha = 0;
[src.navigationController popViewControllerAnimated:NO];
}];
}
I have a custom segue animation that occurs when pushing a new view controller onto the stack. When popping the view controller that was presented with said custom segue, however, the default navigation controller animation happens (that is, the current view controller animates to the right while the parent view controller translates on-screen from the left edge).
So my question is this: is there a way to write a custom pop segue animation which happens when popping a view controller off the stack?
Edit (solution):
I ended up defining a custom segue similar to the selected answer. In the Storyboard, I dragged a custom segue from the child view controller back to its parent, gave it an identifier and the newly written reverse segue as its class. Yes, I realize it is virtually identical to a modal transition. Client requirements necessitated this madness, so before anyone comments, understand that I know one shouldn't have to do this under normal circumstances.
- (void)perform {
UIViewController *src = (UIViewController *)self.sourceViewController;
UIViewController *dest = (UIViewController *)self.destinationViewController;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = src.view.frame;
f.origin.y = f.size.height;
src.view.frame = f;
} completion:^(BOOL finished){
src.view.alpha = 0;
[src.navigationController popViewControllerAnimated:NO];
}];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。这是我弹出到顶层的示例。当您在 Storyboard 中创建 Segue 时。在属性检查器中使用选择或输入新的 segue 类。
如果
您只想弹出一级更改,请使用此自定义转场:
和
@end
Yes. Here is an example where I pop to the top level. When your create the segue in Storyboard. Use select or enter the new new segue class in the attributes inspector.
and
If you want to pop up just one level change use this custom segue:
and
@end
对于现在关注此内容的任何人,iOS 7 允许您以两种方式制作动画:
将 segue 设置为 Push,然后查看下面的代码以了解推送实现。
https://github.com/Dzamir/OldStyleNavigationControllerAnimatedTransition
For anyone following this now, iOS 7 lets you animate both ways:
Set the segue to Push, then see code below for a push implementation.
https://github.com/Dzamir/OldStyleNavigationControllerAnimatedTransition
正如评论者 Linus 指出的那样,提出的其他解决方案将创建 UIViewController 的另一个实例。我认为这里的链接描述了启用反向转场动画的其他替代方案。
http://robsprogramknowledge.blogspot.com/2012/05/back-segues.html
As the commenter Linus pointed out, the other solutions presented will create another instance of the UIViewController. I think this link here describe other alternatives to enabling reverse segue animations.
http://robsprogramknowledge.blogspot.com/2012/05/back-segues.html