【发布时间】:2013-02-18 17:44:51
【问题描述】:
我想知道状态栏何时旋转。接收屏幕旋转通知可能会将事情与“面朝上”和“面朝下”等方向混淆。因此,根据状态栏的方向管理旋转是最简单和最干净的方法。方向改变时如何收到通知?
【问题讨论】:
标签: iphone ios objective-c uiview uistatusbar
我想知道状态栏何时旋转。接收屏幕旋转通知可能会将事情与“面朝上”和“面朝下”等方向混淆。因此,根据状态栏的方向管理旋转是最简单和最干净的方法。方向改变时如何收到通知?
【问题讨论】:
标签: iphone ios objective-c uiview uistatusbar
您需要注册UIApplicationDidChangeStatusBarOrientationNotification 通知。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification {
UIInterfaceOrientation orient = [notification.userInfo[UIApplicationStatusBarOrientationUserInfoKey] integerValue];
// handle the interface orientation as needed
}
请注意,这种方法永远不会导致“面朝上”或“面朝下”的设备方向,因为这只涉及界面方向。
【讨论】:
[[UIApplication sharedApplication] statusBarOrientation] 给了我新的状态栏方向
//register to receive orientation notifications somewhere:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
-(void)detectOrientation{
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationFaceDown:{
}
break;
default:{
}
break;
}
}
如果它不起作用,请检查方向锁定!浪费了几个小时。
【讨论】: