And*_*rew 6 iphone objective-c uiview ios uistatusbar
我想知道状态栏何时旋转.接收屏幕旋转通知可能会使问题与"正面朝上"和"正面朝下"等方向混淆.因此,根据状态栏的方向管理轮换是最简单,最干净的方法.当方向发生变化时,如何收到通知?
rma*_*ddy 12
您需要注册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
}
Run Code Online (Sandbox Code Playgroud)
请注意,此方法永远不会导致"面朝上"或"面朝下"设备方向,因为这只涉及界面方向.
Ada*_*ite -1
//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;
}
}
Run Code Online (Sandbox Code Playgroud)
如果不起作用,请检查方向锁定!浪费了几个小时。
| 归档时间: |
|
| 查看次数: |
4433 次 |
| 最近记录: |