接收方向更改通知时StatusBar方向错误
我有2个视图控制器注册接收设备方向更改通知。 `
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionView)name:UIDeviceOrientationDidChangeNotification object:nil];
`
在重新定位视图方法中我有:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"view (%@) will set orientation landscape",self);
// do smt
} else {
NSLog(@"view (%@) will set orientation portrait",self);
//do smt else
}
当方向改变时,他们都在记忆中
2013-11-27 17:37:54.277 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation landscape
2013-11-27 17:37:54.286 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation portrait
2013-11-27 17:38:17.318 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation portrait
2013-11-27 17:38:20.123 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation landscape
只有一个接收到正确的方向。 为什么是这样 ? 我该如何解决它?
使用UIApplicationDidChangeStatusBarOrientationNotification而不是UIDeviceOrientationDidChangeNotification。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionView:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
-(void)repositionView:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[[notification userInfo] objectForKey: UIApplicationStatusBarOrientationUserInfoKey] integerValue];
if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"view (%@) will set orientation landscape",self);
// do smt
} else {
NSLog(@"view (%@) will set orientation portrait",self);
//do smt else
}
}
链接地址: http://www.djcxy.com/p/66727.html
上一篇: StatusBar orientation wrong when receiving orientation changed notification
下一篇: ACAccountStoreDidChangeNotification is called repeatedly