iOS 导致横屏失败的bug 的原因分析之一

// - 有时我们调用了这个方法 并且实现了屏幕旋转相关的代码但是屏幕还是没有旋转过来 有可能导致这个问题的原因是我们多次调用了移除
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
这个通知的问题 如果加入一次通知 移除一次通知没有问题,但是如果加入过一次通知但是移除通知两次,就会出现问题
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

#pragma mark -  设备旋转
-(BOOL)shouldAutorotate{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

猜你喜欢

转载自blog.csdn.net/qq_27074387/article/details/80494508