多くのビューを持つアプリケーションがあります。デバイスを回転させたときに、いくつかのビューだけを横向きに回転できるようにしたいです。(BOOL)shouldAutorotateToInterfaceOrientation
アプリのすべてのビューが回転するため、使用できないことがわかりました。Stack Overflow でこの問題の解決策を見つけましたが、別の問題に対処する必要があります。
デバイスを回転させるとビューが回転しますが、まだ縦向きモード (まっすぐ上下) にあるかのようにビューが表示されます。ビューの上下が切り取られています。ビューを回転させ、新しい向きに合わせてサイズを調整する方法はありますか? これも見つけましたが、動作させることができませんでした。
そのビューのコードは次のとおりです。
@implementation businessBank
@synthesize webView, activityIndicator;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = @"website_url";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
[self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
} else if (orientation == UIDeviceOrientationLandscapeRight) {
[self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
[self.view setTransform:CGAffineTransformMakeRotation(M_PI)];
} else if (orientation == UIDeviceOrientationPortrait) {
[self.view setTransform:CGAffineTransformMakeRotation(0.0)];
}
}