UIDevice.orientationinclude UIDeviceOrientationFaceUp和 的可能值UIDeviceOrientationFaceDown.虽然知道设备是扁平的可能是有用的,但这并不能告诉我们它是否是平面显示面向纵向或横向模式的界面.有没有办法在设备返回模糊信息的情况下找到GUI的当前方向?我想我可以跟踪方向变化事件以记住最后的纵向/横向方向或检查主要UIView的边界高度和宽度,但这似乎是kludgey.设备或UIView上有一个我失踪的财产吗?
在iOS 5中,我们可以通过编程方式更改设备方向,如下所示:
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
Run Code Online (Sandbox Code Playgroud)
但是在iOS 6 setOrientation中已弃用,我如何在iOS 6中以编程方式更改设备方向?
如何在App Extension中获取设备当前方向,我尝试了以下两种方法但没有成功.
它总是返回UIDeviceOrientationUnknown
[[UIDevice currentDevice] orientation]
Run Code Online (Sandbox Code Playgroud)它显示红色消息,'sharedApplication'在iOS上不可用(App Extension)
[[UIApplication sharedApplication] statusBarOrientation];
Run Code Online (Sandbox Code Playgroud)我还添加了一个观察者,但它没有被调用.
[[NSNotificationCenter defaultCenter] addObserver:self.view selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
- (void)notification_OrientationWillChange:(NSNotification*)n
{
UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue];
if (orientation == UIInterfaceOrientationLandscapeLeft)
[self.textDocumentProxy insertText:@"Left"];
if (orientation == UIInterfaceOrientationLandscapeRight)
[self.textDocumentProxy insertText:@"Right"];
}
Run Code Online (Sandbox Code Playgroud)那么现在如何才能获得当前的设备定位.
keyboard objective-c ios uideviceorientation ios-app-extension