我有一个应用程序有许多视图。我只想让其中几个视图在设备旋转时能够旋转到横向。我发现我不能使用
当我旋转设备时,视图确实旋转了,但它仍然显示为纵向模式(直立)。视图的顶部和底部被裁剪了。是否有一种方法可以使视图旋转并调整其大小以适应新的方向? 我还发现了这个,但无法使其正常工作。
以下是该视图的代码:
(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)];
}
}