我有一个有很多视图的应用程序。我希望只有几个视图能够在设备旋转时旋转到横向。我发现我不能使用(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)];
}
}