// 監聽屏幕旋轉通知(因爲監聽的是狀態欄的方向變化,所以只有支持橫屏的設備纔會收到通知)
[[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)
{ // 橫屏
}
}
支持橫屏的設備才收到監聽,並準確判斷當前屏幕方向
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.