iOS 6 のビュー コントローラーでユーザー インターフェイスの向きに問題があります。基本的に、ポートレート モードとランドスケープ モードの両方をサポートするビュー コントローラーが 1 つあります。これはもちろん問題なく動作しますが、ユーザーがデバイスを回転させることなく、横向きモードと縦向きモードを切り替えるボタンを実装する必要もあります。基本的に、YouTube アプリケーションのビデオ プレーヤーと同じ動作が必要です。
私は使用しようとしました:
[UIApplication sharedApplication] setStatusBarOrientation:animated:]
問題は、これが iOS 5 でのみ正常に機能することです。iOS 6 では、この機能は実装するまで機能しません。
- (NSUInteger)supportedInterfaceOrientations {
return 0;
}
ここで問題が発生します...マスクに0を返すと、ビューコントローラーのビューはコンテンツを自動回転させません(もちろん)。唯一の方法は、次のように手動で回転させることです:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
...
-(void)didRotate:(NSNotification *) notification
{
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation interfaceOrientation;
switch (deviceOrientation) {
case UIDeviceOrientationPortrait:
interfaceOrientation = UIInterfaceOrientationPortrait;
break;
case UIDeviceOrientationLandscapeLeft:
interfaceOrientation = UIInterfaceOrientationLandscapeRight;
break;
case UIDeviceOrientationLandscapeRight:
interfaceOrientation = UIInterfaceOrientationLandscapeLeft;
break;
default:
interfaceOrientation = UIInterfaceOrientationPortrait;
break;
}
if([UIApplication sharedApplication].statusBarOrientation != interfaceOrientation)
[self layoutForInterfaceOrientation:interfaceOrientation];
}
...
- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
[[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:YES];
CGFloat angle = 0.0f;
switch (orientation) {
case UIInterfaceOrientationPortrait:
angle = 0.0f;
break;
case UIInterfaceOrientationLandscapeLeft:
angle = -M_PI / 2;
break;
case UIInterfaceOrientationLandscapeRight:
angle = M_PI / 2;
break;
default:
break;
}
[UIView animateWithDuration:0.3f animations:^(void){
[[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:NO];
[self.view setTransform: CGAffineTransformMakeRotation(angle)];
}];
...
この解決策は私には本当に汚いようです。iOS 6 でボタンを使用してランドスケープ/ポートレート モードを切り替える簡単な方法はありますか?
どうもありがとう!