監(jiān)聽 UIDeviceOrientationDidChangeNotification的廣播,再根據(jù)[[UIDevice currentDevice] orientation]獲取到屏幕的方向。
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為銀川等服務(wù)建站,銀川等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為銀川企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。-(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]; }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。