UIDevice.orientationinclude UIDeviceOrientationFaceUp和 的可能值UIDeviceOrientationFaceDown.虽然知道设备是扁平的可能是有用的,但这并不能告诉我们它是否是平面显示面向纵向或横向模式的界面.有没有办法在设备返回模糊信息的情况下找到GUI的当前方向?我想我可以跟踪方向变化事件以记住最后的纵向/横向方向或检查主要UIView的边界高度和宽度,但这似乎是kludgey.设备或UIView上有一个我失踪的财产吗?
我想在横向和纵向模式下运行应用程序,
如何在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));
}
Run Code Online (Sandbox Code Playgroud)
但是在appdelegate类型的对象上找不到错误属性界面方向.
我怎样才能做到这一点?