gpt4 book ai didi

objective-c - 切换到横向 View 并使用标签栏 Controller

转载 作者:行者123 更新时间:2023-11-29 11:19:03 25 4
gpt4 key购买 nike

我正在为我的应用程序使用标签栏 Controller 。如果我在一个名为“results”的 View Controller 中,并且 ios 设备旋转到横向模式,它会切换到我创建的另一个名为 landScape 的 View 。这已经在方法中完成了

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view=landScape;
} else {
self.view=originalView;
}
}

只要我在选项卡栏中的特定 Controller (示例结果 View Controller )中,它就可以正常工作。然而;如果我转到选项卡栏 Controller 中的另一个元素,并且我的手机在横向模式下倾斜,然后我决定转到 resultsviewcontroller,它不会调用我的 View landScape,而是尝试自行调整 View 大小,它看起来可怕。我应该在 viewDidLoad 方法中调用方法 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 来解决问题吗?或者这是完全错误的?

提前致谢!

最佳答案

问题是当 resultsViewController.view 是事件 View Controller 并检测到旋转时,您才设置它。试试这个:

- (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
self.view = UIInterfaceOrientationIsPortrait(orientation)
? originalView
: landScape;
}

- (void)viewWillAppear
{
[self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
[super viewWillAppear];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
[self setViewForInterfaceOrientation:toInterfaceOrientation];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

关于objective-c - 切换到横向 View 并使用标签栏 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8100549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com