监听UIDeviceOrientationDidChangeNotification的广播,再根据[[UIDevice currentDevice] orientation]获取到屏幕的方向。



-(void)viewDidLoad{//Requesttoturnonaccelerometerandbeginreceivingaccelerometerevents[[UIDevicecurrentDevice]beginGeneratingDeviceOrientationNotifications];[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(orientationChanged:)name:UIDeviceOrientationDidChangeNotificationobject:nil];}-(void)orientationChanged:(NSNotification*)notification{//获取当前屏幕方向interfaceOrientationUIDeviceOrientationorientation=[[UIDevicecurrentDevice]orientation];if(orientation==UIDeviceOrientationLandscapeLeft){//左横屏[selfallPlay];}else{//其他的都是正竖屏[selfnormalPlay];}}-(void)viewDidDisappear{//Requesttostopreceivingaccelerometereventsandturnoffaccelerometer[[NSNotificationCenterdefaultCenter]removeObserver:self];[[UIDevicecurrentDevice]endGeneratingDeviceOrientationNotifications];}-(void)allPlay{//按钮[self.allScreenPlayBtnsetHidden:YES];[self.normalPlayBtnsetHidden:NO];//状态栏isStatusBaeHidden=YES;[selfprefersStatusBarHidden];//是否隐藏状态栏//导航栏[self.navigationControllersetNavigationBarHidden:YESanimated:YES];//view旋转[UIViewbeginAnimations:@"rotate"context:nil];[UIViewsetAnimationDuration:0.6f];[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];self.cbPlayer.view.transform=CGAffineTransformRotate(self.view.transform,M_PI_2);self.normalPlayBtn.transform=CGAffineTransformRotate(self.normalPlayBtn.transform,M_PI_2);[UIViewcommitAnimations];CGSizesize=[[UIScreenmainScreen]bounds].size;CGRectrect=CGRectMake(0,-20,size.width,size.height);[self.cbPlayer.viewsetFrame:rect];}-(void)normalPlay{//按钮[self.allScreenPlayBtnsetHidden:NO];[self.normalPlayBtnsetHidden:YES];//状态栏isStatusBaeHidden=NO;[selfprefersStatusBarHidden];//导航栏[self.navigationControllersetNavigationBarHidden:NOanimated:YES];//view旋转[UIViewbeginAnimations:@"rotate"context:nil];[UIViewsetAnimationDuration:0.6f];[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];self.cbPlayer.view.transform=CGAffineTransformRotate(self.view.transform,0);self.normalPlayBtn.transform=CGAffineTransformRotate(self.normalPlayBtn.transform,0);[UIViewcommitAnimations];[self.cbPlayer.viewsetFrame:self.playView.frame];}