我正在尝试实现一个自定义的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有一个表视图,可供选择的选项很少。选择后,我将打开这些相应的ViewControllers。假设我点击了menu1,然后打开了menu1ViewController,它工作得很好。现在,当我关闭这个viewController时,我调用dismissViewController。
在menuViewController中,我已经编写了menuviewController to bottom的动画代码,它工作得很好。
但是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];
}
}MenuViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(m_test)
{
[self slideIn];
m_test = FALSE;
}
else
{
[self slideOut];
}
}发布于 2012-12-12 18:03:31
-[UIViewController viewWillAppear]和-[UIViewController viewDidAppear]只会在被调用者被像容器一样的控制器添加到视图控制器层次结构的地方被调用,比如导航控制器,选项卡栏控制器。
如果您只是通过在代码中调用addSubview:来添加视图,则不会调用它。See also。
您可以在适当的地方以编程方式在代码中调用-viewWillAppear和-viewDidAppear,在调用addSubview:之前和之后使用或不使用动画。
https://stackoverflow.com/questions/13836963
复制相似问题