正如在SO上的其他问题中所报告的那样,iOS 5根据此发行说明更改了拆分视图控制器的旋转回调的发送方式.这不是一个骗局(我认为),因为我无法找到关于如何在iOS 5中调整拆分视图控制器使用以应对更改的另一个问题:
iOS 5中的旋转回调不适用于通过全屏显示的视图控制器.这意味着,如果你的代码呈现了另一个视图控制器视图控制器,然后用户随后旋转设备,以不同的取向,在解雇,底层控制器(即呈现控制器)将不会收到任何旋转回调.但请注意,呈现控制器在重新显示时将接收viewWillLayoutSubviews调用,并且可以从此方法查询interfaceOrientation属性并用于正确布局控制器.
我在根分割视图控制器中配置弹出窗口按钮时遇到问题(当你在肖像中时,应该在弹出框中显示左窗格视图).以下是当设备处于横向模式时,我的应用启动序列在iOS 4.x中的工作方式:
将拆分视图控制器安装到窗口中[window addSubview:splitViewController.view]; [window makeKeyAndVisible];.这导致在splitViewController:willHideViewController:withBarButtonItem:forPopoverController:委托上调用(即模拟横向 - >纵向旋转),即使设备已处于横向模式.
呈现全屏模式(我的加载屏幕),它完全覆盖下面的分割视图.
完成加载并关闭加载屏幕模式.由于设备处于横向模式,因此在显示分割视图控制器时,这会导致splitViewController:willShowViewController:invalidatingBarButtonItem:在代理上调用(即模拟纵向 - >横向旋转),从而使条形按钮项无效,将其从右侧移除拆分视图,留下我们想要的地方.万岁!
因此,问题在于,由于该发行说明中描述的更改,iOS 4.3内部发生的任何事情都会导致splitViewController:willShowViewController:invalidatingBarButtonItem:被调用不再发生在iOS 5中.我尝试了子类化UISplitViewController,因此我可以提供自定义的实现,viewWillLayoutSubviews如发行说明,但我不知道如何重现iOS 4触发的所需内部事件序列.我试过这个:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
UINavigationController *rightStack = [[self viewControllers] objectAtIndex:1];
UIViewController *rightRoot = [[rightStack viewControllers] objectAtIndex:0];
BOOL rightRootHasButton = ... // determine if bar button item for portrait mode is there
// iOS 4 never goes inside this 'if' branch
if (UIInterfaceOrientationIsLandscape( [self interfaceOrientation] ) …Run Code Online (Sandbox Code Playgroud) 我在肖像模式下有一个UIView作为XIB.
此视图以编程方式添加到viewcontroller,如下所示:
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"InputView" owner:self options:nil];
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
Run Code Online (Sandbox Code Playgroud)
此视图具有正确设置的自动调整遮罩,并且在方向从纵向更改为横向时旋转正常.
但是,如果方向已经是横向,并且我在方向更改后创建视图,则它具有其初始纵向方向.
有没有办法告诉视图使用其掩码初始化或自己调整为肖像?
在此先感谢您的回复!
编辑:使用occulus和Inder Kumar Rathore的建议(谢谢你们!),我将代码改为:
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
[self.view setNeedsLayout];
[self.view layoutSubviews];
[self.view layoutIfNeeded];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[self shouldAutorotateToInterfaceOrientation:orientation];
Run Code Online (Sandbox Code Playgroud)
不幸的是,根本没有变化.我想我发现有人问同样的问题:
答案正确地确定了问题,但并不是非常令人鼓舞......当然,我可以创建两个笔尖或调整框架大小,但这似乎与自动调整大小的想法相反.我觉得很难相信在唤醒之后无法告诉笔尖并将其添加到视图中以使用其自动调整功能......当设备旋转时它会完美无瑕.
编辑2:
idz的解决方案有效:
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
inputView.frame = self.view.bounds;
[inputView show];
Run Code Online (Sandbox Code Playgroud)
谢谢!