【问题标题】:Custom Segue not allowing IBActions in destination controller自定义 Segue 不允许目标控制器中的 IBAction
【发布时间】:2012-09-17 19:13:35
【问题描述】:

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

我使用了自定义的 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 方法只是让应用程序崩溃,例如按下按钮。

【问题讨论】:

    标签: animation segue ibaction superview


    【解决方案1】:

    我通过将代码更改为此解决了我的问题:

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

    正确初始化控制器。 希望这对将来的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 2019-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 2015-08-21
      相关资源
      最近更新 更多