gpt4 book ai didi

iphone - xcode - 如何将 View 锁定为纵向模式,但仍允许一个 View 旋转?

转载 作者:行者123 更新时间:2023-12-03 19:33:00 26 4
gpt4 key购买 nike

我遇到设备旋转问题。除了一个 View (我在其中显示公司初始屏幕)之外,我想将所有剩余的应用程序 View 锁定为纵向显示。在项目设置中,支持的方向是纵向和横向左。在“公司启动画面”中,它工作正常,并且无论我如何旋转设备, View 旋转都被锁定到 LandscapeLeft 中。在所有其他 View 中,当我向左旋转设备时, View 会发生变化,而不是保持纵向显示。这些方法甚至没有触发?如果我从项目中支持的方向中删除横向左侧,则会破坏“公司启动画面” View 。我尝试将 shouldAutorotate 返回更改为 NO,但这没有帮助。尝试按我的方式完成发布的建议here ,但这没有帮助。如果我将以下代码放入 AppDelegate.m 中,所有内容都会锁定为纵向模式,并且“公司启动画面”在访问时会崩溃。

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

无论设备如何旋转(除了一个屏幕),如何将 View 锁定为纵向模式?

** 来自“公司启动” View 的方法。再次,按照预期工作。

-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}

** 来自所有其他 View 的方法,当我不希望它们旋转时,它们会从纵向旋转

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// IOS5 Only returning that it should rotate to potrait
return (interfaceOrientation == UIDeviceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
// forcing the rotate IOS6 Only
return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
// return number or enum IOS6 Only
return UIInterfaceOrientationMaskPortrait;
}

我想可能是因为 UITabBarController 是根 Controller ,而我在 ViewController 中?这些方法甚至没有触发?

最佳答案

将观察者添加到要旋转的 View 的 viewDidLoad 方法中,如下所示:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];

然后根据orientationChanged方法中的横向 View 设置 View ,如下所示:

- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
case UIDeviceOrientationPortrait:

break;
case UIDeviceOrientationPortraitUpsideDown:

break;
case UIDeviceOrientationLandscapeLeft:

break;
case UIDeviceOrientationLandscapeRight:

break;

default:
break;
};
}

关于iphone - xcode - 如何将 View 锁定为纵向模式,但仍允许一个 View 旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15110838/

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