【发布时间】:2014-08-23 12:49:24
【问题描述】:
如何在应用扩展中获取设备当前方向,我尝试了以下两种方法,但都没有成功。
-
它总是返回 UIDeviceOrientationUnknown
[[UIDevice currentDevice] orientation] -
它显示红色消息“sharedApplication”在 iOS 上不可用(应用程序扩展)
[[UIApplication sharedApplication] statusBarOrientation]; -
我还添加了一个观察者,但它没有被调用。
[[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"]; }
那么现在任何人如何才能获得当前的设备方向。
【问题讨论】:
-
你用的是哪个ios?
-
Xcode6 beta4 与 iOS8
-
Apple 从 iOS 8 开始不再使用设备方向。请查看尺寸等级。
-
我发现这个答案很有帮助:stackoverflow.com/questions/29528661/…
标签: ios objective-c keyboard ios-app-extension uideviceorientation