Animation 自定义Segue不允许目标控制器中的iActions
我有两个带有视图的视图控制器。第一个屏幕是登录屏幕,第二个屏幕从web获取内容(不相关) 我使用了一个自定义的segue动画,不得不对superview做一些奇怪的事情,以使sourceViewController.view在destinationViewController.view的“顶部”(视觉上) 我只能假设这就是为什么当我试图从第二个视图调用iAction方法时,它们不会调用 以下是segue类的实现:Animation 自定义Segue不允许目标控制器中的iActions,animation,segue,ibaction,superview,Animation,Segue,Ibaction,Superview,我有两个带有视图的视图控制器。第一个屏幕是登录屏幕,第二个屏幕从web获取内容(不相关) 我使用了一个自定义的segue动画,不得不对superview做一些奇怪的事情,以使sourceViewController.view在destinationViewController.view的“顶部”(视觉上) 我只能假设这就是为什么当我试图从第二个视图调用iAction方法时,它们不会调用 以下是segue类的实现: - (void) perform { UIViewController
- (void) perform {
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
UIView *parent = sourceViewController.view.superview;
[sourceViewController.view removeFromSuperview];
[parent addSubview: destinationViewController.view];
[parent addSubview:sourceViewController.view];
sourceViewController.view.layer.masksToBounds = NO;
sourceViewController.view.layer.cornerRadius = 8; // if you like rounded corners
sourceViewController.view.layer.shadowOffset = CGSizeMake(0,0);
sourceViewController.view.layer.shadowRadius = 10;
sourceViewController.view.layer.shadowOpacity = 1;
destinationViewController.view.frame = CGRectMake(0, 20, destinationViewController.view.frame.size.width, destinationViewController.view.frame.size.height);
sourceViewController.view.frame = CGRectMake(0, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
[UIView animateWithDuration:.6
delay:0.0
options:UIViewAnimationCurveEaseInOut
animations:^{
sourceViewController.view.frame = CGRectMake(-sourceViewController.view.frame.size.width-10, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
}
completion:^(BOOL finished){
//[destinationViewController.view removeFromSuperview];
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}];
}
我的问题是,将源代码视图从它的超级视图中移除,然后玩弄它会破坏第二个视图中调用iActions的方式吗
iAction方法只是在按下按钮时使应用程序崩溃。我通过将代码更改为以下内容解决了问题:
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
UIView *parent = sourceViewController.view.superview;
[parent addSubview:destinationViewController.view];
[parent sendSubviewToBack: destinationViewController.view];
sourceViewController.view.layer.masksToBounds = NO;
sourceViewController.view.layer.cornerRadius = 8; // if you like rounded corners
sourceViewController.view.layer.shadowOffset = CGSizeMake(0,0);
sourceViewController.view.layer.shadowRadius = 10;
sourceViewController.view.layer.shadowOpacity = 1;
destinationViewController.view.frame = CGRectMake(0, 20, destinationViewController.view.frame.size.width, destinationViewController.view.frame.size.height);
sourceViewController.view.frame = CGRectMake(0, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
[UIView animateWithDuration:.6
delay:0.0
options:UIViewAnimationCurveEaseInOut
animations:^{
sourceViewController.view.frame = CGRectMake(-sourceViewController.view.frame.size.width-10, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
}
completion:^(BOOL finished){
[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];
}];
有些事情改变了,但值得注意的是,我
[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];
正确初始化控制器。
希望这能在将来帮助其他人