0

我正在尝试实现自定义 UIActionSheet(由 ViewController 组成)我已将 View Controller 作为 subView 添加到我的 rootView 的 navigationcontroller

- (IBAction)ShowMenu:(id)sender
{
   [self.navigationController.view addSubview:self.menuViewController.view];
   [self.menuViewController setTest:YES];
   [self.menuViewController viewWillAppear:YES];
}

这里 MenuViewController 有一个 tableview 有几个选项可供选择。选择后,我将打开那些各自的 ViewController。假设我点击 menu1 然后打开 menu1ViewController 并且它工作正常。现在当我关闭这个 viewController 时,我正在调用dismissViewController。

在 menuViewController 中,我编写了代码以通过 menuviewController 设置动画到底部,并且效果很好。

但是 MenuView 的父级是 TestViewController ,当 menuviewController 动画下来时,不会调用函数 viewdidAppear 。

这就是我的问题,

我正在使用此代码通过 menuViewController 设置动画到底部

- (void) slideOut {


  [UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];

    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    // Move this view to bottom of superview
    CGRect frame = self.menusheet.frame;
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
    self.menusheet.frame = frame;

    [UIView commitAnimations];
}

// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [self.view removeFromSuperview];
    }
}

菜单视图控制器

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if(m_test)
    {
        [self slideIn];
        m_test = FALSE;
    }
    else
    {
        [self slideOut];       
    }

}
4

1 回答 1

3

恕我直言,-[UIViewController viewWillAppear]并且-[UIViewController viewDidAppear]只会在被调用者被那些类似容器的控制器(如导航控制器、标签栏控制器)添加到视图控制器层次结构中时被调用。

addSubview:如果您只是通过调用代码来添加视图,则不会调用它。另请参阅

您可以在调用之前和之后使用或不使用动画在代码中以编程方式调用-viewWillAppear并在适当的情况下调用。-viewDidAppearaddSubview:

于 2012-12-12T10:03:30.940 回答