gpt4 book ai didi

objective-c - View 应仅显示为纵向模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:40 25 4
gpt4 key购买 nike

我有一个支持旋转到横向模式的 View Controller (VC1)。但是在下一个 View (VC2)中,我只想让它以纵向模式出现,我的意思是如果用户在横向模式下使用 VC1 并转到 VC2,那么它的 View 将根据横向边界设置它们的框架。我不想要这个,我希望 View 应该旋转 90 度,就像在用户已经处于纵向模式的 VC2 中然后将设备方向更改为横向并且 VC2 不支持自动旋转时出现的情况一样。

我注意到只有当父 View Controller 也不支持自动旋转时才会发生这种情况。如果父 View 不支持自动旋转,则在横向模式下推送或呈现时, subview 将旋转 90 度。

最佳答案

我解决这个问题的方法是让整个项目只显示为纵向,并且在我需要旋转的 View 上,我会在 viewDidLoad 中设置一个 NSNotifier,如下所示。

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

然后我会像这样处理方向的变化:

-(void)handleOrientationDidChange:(NSNotification *)notification
{
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Change view frame to fit landscape mode and rotate
} else {
// Reset view frame to fit portrait mode and rotate back to orignal position
}

我不知道这是否符合您的需求,但它是我处理 VC1 需要轮换但 VC2+ 不需要轮换的情况的方式。

关于objective-c - View 应仅显示为纵向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13874953/

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