gpt4 book ai didi

iphone - 旋转 View 时不触发 UIInterfaceOrientationIsLandscape

转载 作者:行者123 更新时间:2023-12-03 20:23:31 25 4
gpt4 key购买 nike

我正在尝试让我的应用程序能够横向和纵向工作。我在所有 View Controller 中安装了正确的方法,并且当 ipad 模拟器旋转时此代码会触发,但总是触发纵向。景观 IF 子句永远不会被触发。我可能做错了什么?

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation {
NSLog(@"******* ROTATING ******");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {

NSLog(@"ROTATING View Landscape ******");

} else if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {

NSLog(@"ROTATING View Portrait ******");

}
}

}

最佳答案

设备和界面方向似乎是不同的。我在 Apple 网站上找到了使用 UIDeviceOrientation 执行此操作的方法。使用此测试,当我旋转模拟器和我的 ipad 设备时,我会得到正确的触发器。

    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

if (UIDeviceOrientationIsLandscape(deviceOrientation))

{


}

else if (deviceOrientation == UIDeviceOrientationPortrait)

{

}

关于iphone - 旋转 View 时不触发 UIInterfaceOrientationIsLandscape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5404780/

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