切换到横向视图并使用选项卡栏控制器
我正在为我的应用程序使用标签栏控制器。如果我在一个名为“结果”的视图控制器中,并且 ios 设备旋转到横向模式,它会切换到我创建的另一个名为 landScape 的视图。这是在方法中完成的
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view=landScape;
} else {
self.view=originalView;
}
}
,只要我位于选项卡栏内的特定控制器(示例结果视图控制器)中,它就可以正常工作。然而;如果我转到选项卡栏控制器中的另一个元素,并且我的手机在横向模式下倾斜,然后我决定转到 resultsviewcontroller,它不会调用我的视图 landScape,而是尝试自行自动调整视图大小,并且看起来可怕。我应该在 viewDidLoad 方法中调用方法 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationuration:(NSTimeInterval)duration 来解决问题吗?或者这是完全错误的?
先感谢您!
I am using a tab bar controller for my app. If I'm in one of the view controllers called "results" and the ios device rotates to landscape mode, it switches for another view I created called landScape. This has been done within the method
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view=landScape;
} else {
self.view=originalView;
}
}
It works just fine whenever I am in that specific controller within the tab bar (example results view controller). However; If I go to another element in my tab bar controller and my phone is tilted in landscape mode and then I decide to go to resultsviewcontroller, it does not call upon my view landScape, instead it tries to autosize the view on its own and it looks awful. Should I call the method -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration within my viewDidLoad method to solve the problem? Or is this completely wrong?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您仅在
resultsViewController.view
是活动视图控制器并检测到旋转时才设置它。试试这个:The problem is you're only setting
resultsViewController.view
when it is the active view controller and detects a rotation. Try this: