OC回転画面は最初は、デバイスの向きを開くことで、二つの部分に分け、その後、独自の回転、不要に手動でオープン処理を開きました。ほとんどは通常、これよりも少ないと、最近AVFoundationを見て、自動レイアウトであるため、これを使用する必要があり、関連するものなので、要約します
最初の部分は、自動回転を開きます。
- (1)登録画面の回転を通知します。
[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]。 //注册屏幕旋转通知 [NSNotificationCenter defaultCenter] addObserver:自己 セレクタ:@selector(orientChange :) 名:UIDeviceOrientationDidChangeNotificationの オブジェクト:[UIDevice currentDevice]。
- (ボイド)orientChange:(NSNotification *)通知{ UIDeviceOrientation配向= [UIDevice currentDevice] .orientation。 (配向== UIDeviceOrientationPortrait){場合 のNSLog(@ "ホーム在下方"); self.deviceOrientationBtn.selected = NO; }それ以外の場合(配向== UIDeviceOrientationPortraitUpsideDown){ のNSLog( "ホーム在上方" @)。 self.deviceOrientationBtn.selected = NO; }それ以外の場合(配向== UIDeviceOrientationLandscapeLeft){ のNSLog( "ホーム在右方" @)。 self.deviceOrientationBtn.selected = YES; }それ以外の場合(配向== UIDeviceOrientationLandscapeRight){ のNSLog( "ホーム在左方" @)。 self.deviceOrientationBtn.selected = YES。
私は手動で横画面または垂直画面を回した後、あなたはまた、強制コードを使用することができますしたい場合:
[UIDevice currentDevice]のsetValue:のNSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight]
または
[[UIDevice currentDevice]のsetValue:[のNSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@ "オリエンテーション"]
あなたは横画面縦画面上のViewControllerを入力または変更したい場合は、撤退後に再開し、することができます
- (無効)viewWillAppear:(BOOL)アニメーション
そして
- (無効)viewWillDisappear:(BOOL)アニメーション:
達成するために、2つの方法
第二部は、画面の回転を開けないでください、あなたは手動で代わりに偽を行う必要があります
(1)方法横画面の設定:
- (ボイド)fullScreenWithDirection:(UIInterfaceOrientation方向){ IF(方向== UIInterfaceOrientationLandscapeLeft){ [[のUIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRightアニメーション:YES]。 [UIViewのanimateWithDuration:0.25アニメーション:^ { self.view.transform = CGAffineTransformMakeRotation(M_PI / 2)。 }完了:^(BOOL終了){ // [自己setFullStatusBarHiddenType:_fullStatusBarHiddenType]。 }]。 }そうであれば(方向== UIInterfaceOrientationLandscapeRight){ [[のUIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeftアニメーション:YES]。 [UIViewのanimateWithDuration:0.25アニメーション:^ { self.view.transform = CGAffineTransformMakeRotation(0)。 }完了:^(BOOL終了){ // [自己setFullStatusBarHiddenType:_fullStatusBarHiddenType]。 }]。 } self.view.frame = [のUIApplication sharedApplication] keyWindow] .bounds。 [self.view setNeedsLayout]。 [self.view layoutIfNeeded]。 }
(2)還元肖像
[UIViewのanimateWithDuration:0.25アニメーション:^ { self.view.transform = CGAffineTransformMakeRotation(0)。 self.view.frame = [のUIApplication sharedApplication] keyWindow] .bounds。 [self.view setNeedsLayout]。 [self.view layoutIfNeeded]。 }完了:^(BOOL終了){ }]。