監(jiān)聽 UIDeviceOrientationDidChangeNotification的廣播,再根據(jù)[[UIDevice currentDevice] orientation]獲取到屏幕的方向。
公司主營業(yè)務(wù):網(wǎng)站制作、成都網(wǎng)站建設(shè)、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出臨高免費(fèi)做網(wǎng)站回饋大家。
-(void) viewDidLoad { // Request to turn on accelerometer and begin receiving accelerometer events [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)orientationChanged:(NSNotification *)notification { // 獲取當(dāng)前屏幕方向interfaceOrientation UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if (orientation == UIDeviceOrientationLandscapeLeft) {// 左橫屏 [self allPlay]; } else {// 其他的都是正豎屏 [self normalPlay]; } } -(void) viewDidDisappear { // Request to stop receiving accelerometer events and turn off accelerometer [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; } - (void) allPlay { // 按鈕 [self.allScreenPlayBtn setHidden:YES]; [self.normalPlayBtn setHidden:NO]; // 狀態(tài)欄 isStatusBaeHidden = YES; [self prefersStatusBarHidden]; // 是否隱藏狀態(tài)欄 // 導(dǎo)航欄 [self.navigationController setNavigationBarHidden:YES animated:YES]; // view旋轉(zhuǎn) [UIView beginAnimations:@"rotate" context:nil]; [UIView setAnimationDuration:0.6f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; self.cbPlayer.view.transform = CGAffineTransformRotate(self.view.transform, M_PI_2); self.normalPlayBtn.transform = CGAffineTransformRotate(self.normalPlayBtn.transform, M_PI_2); [UIView commitAnimations]; CGSize size = [[UIScreen mainScreen] bounds].size; CGRect rect = CGRectMake(0, -20, size.width, size.height); [self.cbPlayer.view setFrame:rect]; } - (void) normalPlay { // 按鈕 [self.allScreenPlayBtn setHidden:NO]; [self.normalPlayBtn setHidden:YES]; // 狀態(tài)欄 isStatusBaeHidden = NO; [self prefersStatusBarHidden]; // 導(dǎo)航欄 [self.navigationController setNavigationBarHidden:NO animated:YES]; // view旋轉(zhuǎn) [UIView beginAnimations:@"rotate" context:nil]; [UIView setAnimationDuration:0.6f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; self.cbPlayer.view.transform = CGAffineTransformRotate(self.view.transform, 0); self.normalPlayBtn.transform = CGAffineTransformRotate(self.normalPlayBtn.transform, 0); [UIView commitAnimations]; [self.cbPlayer.view setFrame:self.playView.frame]; }
新聞標(biāo)題:IOS學(xué)習(xí)之響應(yīng)設(shè)備的橫豎屏狀態(tài),旋轉(zhuǎn)界面達(dá)到橫豎屏效果
網(wǎng)站路徑:http://bm7419.com/article20/pssjjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、云服務(wù)器、網(wǎng)站設(shè)計(jì)公司、軟件開發(fā)、App設(shè)計(jì)、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)