转发前两个答案,这里有关于目标c版本的更多细节(我也只有Objective-C代码)
使用 UIStoryboardSegueWithCompletion 子类化 UIStoryboardSegue
类 UIStoryboardSegueWithCompletion: UIStoryboardSegue { var 完成: (() -> Void)?
override func perform() {
super.perform()
if let completion = completion {
completion()
}
}
}
UIStoryboardSegueWithCompletion.h
#import <UIKit/UIKit.h>
@interface MyStoryboardSegue : UIStoryboardSegueWithCompletion
@property (nonatomic, copy) void(^completion)();
@end
UIStoryboardSegueWithCompletion.m
#import "UIStoryboardSegueWithCompletion.h"
@implementation UIStoryboardSegueWithCompletion
- (void)perform {
[super perform];
if (self.completion != nil) {
[self.destinationViewController.transitionCoordinator
animateAlongsideTransition:nil
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
if (![context isCancelled]) {
self.completion();
}
}];
}
}
@end
- 将 UIStoryBoardSegueWithCompletion 设置为退出 segue 的类
注意:此 segue 的操作应该是 unwindToMainMenu 以匹配原始问题 [显示 segue ui 的图像][1] [显示 segue ui 2 的图像][2]
从情节提要中选择退出 segue 添加自定义类
-(IBAction)unwindToMainMenu(UIStoryboardSegue *)segue {
if([segue isKindOfClass:[UIStoryboardSegueWithCompletion class]]){
UIStoryboardSegueWithCompletion *segtemp = segue;// local prevents warning
segtemp.completion = ^{
NSLog(@"segue completion");
[self performSegueWithIdentifier:@"Categories" sender:self];
};
}
}
您的代码现在将在 exit segue 完成其转换后执行