自定义UIViewController子视图不旋转,但superview确实,帮我解决原因?

Coc*_*ica 0 cocoa-touch uiviewcontroller uikit ipad autorotate

简单的iPad应用.

App加载并显示由UIViewController的子类控制的UITableView.这工作和旋转完美.

单击表视图中的行会导致创建新的子视图,该子视图也由UIViewController子类控制.这在纵向显示良好,但不适应横向,并且不响应设备旋转.

两个视图控制器都包括:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    NSLog(@"Responding to rotation");
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

但是只有原始视图控制器响应:

   - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"View About to rotate");
}
Run Code Online (Sandbox Code Playgroud)

在IB中,我检查了视图是否会自动调整,其中的组件(UIScrollView和一些UILabels)将正确调整.

任何人都可以帮我解决为什么子视图没有响应.

Coc*_*ica 5

我找到了我朋友的答案......

我通过使用将子视图添加到视图中

[mainView.view.window addSubview detailView.view];
Run Code Online (Sandbox Code Playgroud)

然而,这是将它添加到窗口而不是视图,因为窗口只将旋转事件传递给一个视图控制器,我将我的子视图放在错误的位置.相反,我将其更改为......

[mainView.view addSubview detailView.view];
Run Code Online (Sandbox Code Playgroud)

哪个有效!只需要在旋转时添加用于调整子视图大小的代码并完成.

在这里查看更多信息:http://developer.apple.com/iphone/library/qa/qa2010/qa1688.html