我有一个UIViewController
,我用它来控制在整个应用程序中查看图像的“弹出”视图。它支持自动旋转,因为它会自动调整图像的大小以适合不管方向。这工作完美,但只有我第一次初始化和显示视图控制器。当它关闭时,我从我的视图层次结构中删除UIView
,并释放视图控制器 - 但是当我下次实例化并将其添加到我的视图层次结构中时,它将在手机旋转时停止接收-shouldAutorotateToInterfaceOrientation
消息。视图控制器没有收到-shouldAutorotateToInterfaceOrientation:第二次加载的消息?
这是我的实例并显示它:
popupVC = [[PopupVC alloc] init];
[popupVC viewWillAppear:NO];
[[[UIApplication sharedApplication] keyWindow] addSubview:popupVC.view];
[popupVC viewDidAppear:NO];
我这是怎么删除/释放它时,它的完成:
[popupVC viewWillDisappear:NO];
[popupVC.view removeFromSuperview];
[popupVC viewDidDisappear:NO];
[popupVC release];
popupVC = nil;
我已经试过循环通过[[UIApplication sharedApplication] keyWindow]
子视图以查看是否不知何故,我的弹出式视图不在顶部,但始终如此。它每次都有一个不同的地址,所以我知道它是视图控制器类的不同实例。
按照要求,下面是完整的loadView
方法从PopupVC
:
- (void)loadView {
UIView *myView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
myView.backgroundColor = self.overlayColor;
myView.autoresizesSubviews = NO;
myView.hidden = YES;
myView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view = myView;
[myView release];
_isVisible = NO;
UIView *myMaskView = [[UIView alloc] initWithFrame:self.view.bounds];
myMaskView.backgroundColor = [UIColor clearColor];
myMaskView.clipsToBounds = YES;
myMaskView.hidden = YES;
myMaskView.autoresizesSubviews = NO;
myMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:myMaskView];
self.imageMaskView = myMaskView;
[myMaskView release];
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
myImageView.center = self.view.center;
myImageView.hidden = NO;
myImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight;
[self.imageMaskView addSubview:myImageView];
self.imageView = myImageView;
[myImageView release];
UIButton *myImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
myImageButton.frame = self.view.frame;
myImageButton.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight;
[myImageButton addTarget:self action:@selector(clickImage:) forControlEvents:UIControlEventTouchUpInside];
[self.imageMaskView addSubview:myImageButton];
self.imageButton = myImageButton;
UIActivityIndicatorView *myActivityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
myActivityView.hidden = YES;
[self.view addSubview:myActivityView];
myActivityView.center = self.view.center;
self.activityView = myActivityView;
[myActivityView release];
}
你什么时候设置视图控制器?另外,我不相信你需要明确地调用'viewWillAppear:',除非整个问题都是为了防止动画。 – 2009-09-30 19:24:12
当用户选择要显示的图像时,我在'UITableViewDelegate'方法中设置它。我的'PopupVC -loadView'方法设置它使用的视图和子视图。除非发送消息,否则我发现我的'UITabBarController'无法正常工作,所以明确调用了'-viewWillAppear:'后,我只是习惯了。 – pix0r 2009-09-30 19:33:41
你不应该自己调用这些viewWillAppear/viewDidAppear方法。我认为你需要重新思考你如何初始化和清理你的弹出窗口。 – 2009-10-08 16:57:14