gpt4 book ai didi

iphone - 如何在appdelegate上检查横向和纵向模式?

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

我想以横向和纵向模式运行应用程序,

如何在Appdelegate上检查横向和纵向模式?

我尝试打电话

- (BOOL) isPad{ 
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([self isPad]) {
NSLog(@"is pad method call");
return YES;
}
else
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

}



- (BOOL)isPadPortrait
{

return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationPortrait
|| self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}


- (BOOL)isPadLandscape
{

return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));

}

但给出错误在 appdelegate 类型的对象上找不到属性接口(interface)方向。

我怎样才能做到这一点?

最佳答案

您应该检查 iPad 的当前使用方向。我建议您在每个 View 上检查这些条件并根据当前方向采取行动:

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
//Do what you want in Landscape Left
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
//Do what you want in Landscape Right
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
//Do what you want in Portrait
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do what you want in Portrait Upside Down
}

希望这对您有帮助。 :)

如果您需要任何帮助,请随时与我联系。

关于iphone - 如何在appdelegate上检查横向和纵向模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7305757/

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