自定义Segue不允许在目标控制器中执行IBActions



我有两个带视图的视图控制器。第一个是登录屏幕,第二个是从网络上获取内容(无关)。

我使用了一个自定义的segue动画,不得不对superview做一些奇怪的事情,以使sourceViewController.view"位于"destinationViewController.view 的"顶部"(视觉上)

我只能假设这就是为什么当我试图从第二个视图调用IBAction方法时,它们不会调用的原因。

下面是segue类的实现:

- (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];
}];
}

我的问题是,将源视图从其超视图中删除并玩弄它会破坏在第二个视图中调用IBActions的方式吗?

IBAction方法只是在按下按钮时使应用程序崩溃。

我通过将代码更改为来解决问题

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];

以正确初始化控制器。希望这能在未来帮助其他人。

最新更新