我为PopoverController创建了自己的类(没有子类化UIPopoverController)以我想要的方式呈现ViewControllers。
CustomPopoverController不是UIViewController,而是有一个名为“contentViewController”的ivar,它是实际显示的VC。
当用户点击contentViewController框架之外的任何地方时,我实现了自己的“dismissPopoverAnimated:”以关闭我的自定义弹出窗口:
-(void) dismissPopoverAnimated : (BOOL) animated
{
// dismissalView is the view that intercept the taps outside.
[self.dismissalView removeFromSuperview];
self.dismissalView = nil;
if (animated)
{
CGRect newFrame = self.view.frame;
// When in landscape Mode the width of the screen is actually the "height"
newFrame.origin.y = [UIScreen mainScreen].bounds.size.width;
[UIView animateWithDuration:0.5
animations:^{self.view.frame = newFrame;}
completion: ^(BOOL finished) {if(finished) [self.contentViewController.view removeFromSuperview];}];
}
else
{
[self.contentViewController.view removeFromSuperview];
}
isPresented = NO;
[self.delegate customPopoverDidDismissPopover:self];
}
问题是,即使在任何情况下调用removeFromSuperView
- 动画与否,contentViewController
也永远不会收到viewWillDisappear
,viewDidDisappear
甚至{{1}当我发布viewDidUnload
时;
有谁知道为什么? 或者甚至更好地对viewWill ... / viewDid ...方法链以及它们应该被调用的时间点亮一些。
答案 0 :(得分:10)
当你通过UIView的方法添加子视图或删除子视图时,它永远不会导致拥有UIViewController
个人viewWillAppear
,viewDidAppear
,viewWillDisappear
和viewDidDisapper
。只有那些由UINavigationController
方法管理的viewController,如pushViewController:animated:
或popViewControllerAnimated:
,或presentModelViewController:aniamted:
...等等。他们会通知有关状态正在变化的视图控制器。