監(jiān)聽 UIDeviceOrientationDidChangeNotification的廣播,再根據(jù)[[UIDevice currentDevice] orientation]獲取到屏幕的方向。
公司主營業(yè)務:網(wǎng)站制作、成都網(wǎng)站建設、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出臨高免費做網(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 { // 獲取當前屏幕方向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)欄 // 導航欄 [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]; // 導航欄 [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]; }