我有一个自定义的 segue 动画,它在将新的 View Controller 插入堆栈时发生。然而,当弹出带有所述自定义 segue 的 View Controller 时,会发生默认的导航 Controller 动画(即,当前 View Controller 向右动画,而父 View Controller 从左边缘在屏幕上平移)。
所以我的问题是:有没有一种方法可以编写自定义的 pop segue 动画,该动画在从堆栈中弹出 View Controller 时发生?
编辑(解决方案):
我最终定义了一个类似于所选答案的自定义转场。在 Storyboard 中,我将一个自定义转场从 subview Controller 拖回到其父 View Controller ,给它一个标识符,并将新编写的反向转场作为其类。是的,我意识到它实际上与模态转换相同。客户要求使这种疯狂成为必要,因此在任何人发表评论之前,请理解我知道在正常情况下不应该这样做。
- (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];
}];
}
最佳答案
是的。这是我弹出到顶层的示例。当您在 Storyboard 中创建 segue 时。在属性检查器中使用选择或输入新的新 segue 类。
//
// FlipTopPop.h
#import <UIKit/UIKit.h>
@interface FlipTopPopToRoot : UIStoryboardSegue
@end
和
// FlipTopPop.m
#import "FlipTopPopToRoot.h"
@implementation FlipTopPopToRoot
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
[UIView transitionWithView:src.navigationController.view duration:0.5
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
}
completion:NULL];
}
@end
如果您只想弹出一个级别的更改,请使用此自定义转场:
// PopSegue.h
#import <UIKit/UIKit.h>
@interface PopSegue : UIStoryboardSegue
@end
和
// PopSegue.m
#import "PopSegue.h"
@implementation PopSegue
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
[src.navigationController popViewControllerAnimated:YES];
}
@结束
关于objective-c - 用 Storyboard反转自定义 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316233/