// 监听屏幕旋转通知(因为监听的是状态栏的方向变化,所以只有支持横屏的设备才会收到通知)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doRotateAction:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
#pragma mark - 屏幕旋转监听后方法
- (void)doRotateAction:(NSNotification *)notification
{
// 此时根据当前的设备方向来判断是横屏还是竖屏更加准确
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{ // 竖屏
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{ // 横屏
}
}
支持横屏的设备才收到监听,并准确判断当前屏幕方向
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.