gpt4 book ai didi

iphone - 手动检测横向旋转

转载 作者:行者123 更新时间:2023-12-03 18:28:21 25 4
gpt4 key购买 nike

我正在为每个页面开发一个基于 UITabBarController 和 UIViewControllers 的 iPhone 应用程序。该应用程序只需要在纵向模式下运行,因此每个 View Controller +应用程序委托(delegate)都带有这行代码:

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

有一个 View Controller ,当 iPhone 向左旋转时,我想在其中弹出一个 UIImageView。尽管宽度和高度均为 320x460(因此是纵向),但图像的设计看起来是横向的。

我如何/应该在这个特定的 View Controller 中手动检测这种类型的旋转,而不在整个 View 上进行自动旋转?

托马斯

更新:

谢谢!

我在 viewDidLoad 中添加了这个监听器:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)name:UIDeviceOrientationDidChangeNotification object:nil];

didRotate 看起来像这样:

- (void) didRotate:(NSNotification *)notification

{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft)
{
//your code here

}
}

最佳答案

我在一个旧项目中需要它 - 希望它仍然有效......

1)注册通知:

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

2)然后您可以针对变化时的旋转进行测试:

-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
[self doLandscapeThings];
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
[self doPortraitThings];
}
}

希望有帮助!

关于iphone - 手动检测横向旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3005389/

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