gpt4 book ai didi

iphone - 在不需要的 View 中触发替代景观

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

我有一个包含图像和表格 View 的 View Controller 。从这个 View Controller 中,我将 Segue 连接到包含全屏图像的横向 View (当您横向转动 Apple 的 Stocks 应用程序以全屏查看图形时使用相同的想法)。

这个segue通过以下方法调用:

- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissViewControllerAnimated:YES completion:nil];
isShowingLandscapeView = NO;
}
}

除此之外,当 iPhone 处于纵向时,我还可以将桌面 View 向下钻取更多级别。问题如下:在随后的级别上,当我将方向转向横向时,仍然会触发横向 View 的转场!...我该怎么做才能避免这种情况发生?我只对从包含图像的第一个 View 进入横向模式感兴趣。

提前谢谢您!

最佳答案

我不确定我是否正确解决了您的问题..但如果您的意思是“向下钻取表格 View ”以更深入地了解导航 Controller 层次结构,您可以尝试以下操作..

这就是我在(我认为)类似情况下所做的:

应用程序委托(delegate):

在.h中:

@property (nonatomic) BOOL shouldAutorotate;

以 .m 为单位:

//在 didFinishLaunchingWithOptions 中:

self.shouldAutorotate = NO;

//仍在.m文件中

// Autorotation handling
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return self.shouldAutorotate ?
UIInterfaceOrientationMaskAllButUpsideDown :
UIInterfaceOrientationMaskPortrait;
}

导航 Controller 呈现肖像 Controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];

return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotate
{
return YES;
}

肖像 View Controller (这里还有一个非常相似的 segue 处理):

在 viewWillAppear 中:

[(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldAutorotate:YES];

旋转处理:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

横向 View Controller (可能是您的全屏图像):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

导航 Controller 层次结构的更深处(仅需要纵向):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

看起来有点复杂,但这是唯一的方法,我设法让这些轮换在 iOS5 和 6 中正常工作。

关于iphone - 在不需要的 View 中触发替代景观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14650127/

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