我一直在尝试创建一个 UIStoryboardSegue,它模仿“Cover Vertical”模态 segue,但使视图“Uncover”,以便这些 segues 看起来很自然。这是我的 UIStoryboardSegue 子类:
//RetreatVertical.m
#import "RetreatVertical.h"
@implementation RetreatVertical
-(void)perform {
UIView *oldView = [self.sourceViewController view];
UIView *newView = [self.destinationViewController view];
[oldView.window insertSubview:newView belowSubview:oldView];
[UIView animateWithDuration:0.3 animations:^{
oldView.center = CGPointMake(oldView.center.x, oldView.center.y + oldView.frame.size.height); }
completion:^(BOOL finished){ [oldView removeFromSuperview]; }
];
}
@end
当用户点击一个按钮时,UIViewController 使用模态 segue “Cover Vertical”滑入焦点。当用户点击新 UIViewController 上的按钮时,该 UIViewController 会向下滑动,显示旧的 UIViewController(使用我的自定义 segue“RetreatVertical”)。这一切都很好,但是,每当我在两个动画完成后点击任何其他按钮或界面元素时,应用程序都会因“EXC_BAD_ACCESS”而崩溃。我不知道为什么,过去一小时的搜索没有找到任何结果。
谢谢!
编辑: 为什么这个策略不起作用?
- (void) perform {
UIView *sourceView = [self.sourceViewController view];
UIView *destView = [self.destinationViewController view];
[[self.sourceViewController superview] insertSubview:destView belowSubview:sourceView];
[UIView animateWithDuration:0.3 animations:^{
sourceView.center = CGPointMake(sourceView.center.x, sourceView.center.y + sourceView.frame.size.height); }
completion:^(BOOL finished){ [sourceView removeFromSuperview]; }
];
}