-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//開(kāi)始生成 設(shè)備旋轉(zhuǎn) 通知
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//添加 設(shè)備旋轉(zhuǎn) 通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// 銷(xiāo)毀 設(shè)備旋轉(zhuǎn) 通知
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil ];
// 結(jié)束 設(shè)備旋轉(zhuǎn)通知
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
/**屏幕旋轉(zhuǎn)的通知回調(diào)*/
- (void)orientChange:(NSNotification *)noti {
UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
switch (orient) {
case UIDeviceOrientationPortrait:
NSLog(@"豎直屏幕");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"手機(jī)左轉(zhuǎn)");
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"手機(jī)豎直");
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"手機(jī)右轉(zhuǎn)");
break;
case UIDeviceOrientationUnknown:
NSLog(@"未知");
break;
case UIDeviceOrientationFaceUp:
NSLog(@"手機(jī)屏幕朝上");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"手機(jī)屏幕朝下");
break;
default:
break;
}
}
iOS 手機(jī)屏幕旋轉(zhuǎn)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 導(dǎo)入 : #import <CoreMotion/CoreMotion.h> 增加屬性: 初始化: 在真機(jī)關(guān)閉屏幕...
- - (void)viewWillAppear:(BOOL)animated{ [super viewWillApp...
- 功能需求:看視頻時(shí),因?yàn)橐曨l頁(yè)面都是自定義的,這里只是用了第三方的播放控件,為啥播放也不自己寫(xiě)音視頻(哎,這塊不是...