6 iphone resize rotation orientation
我有一个有很多观点的应用程序.我希望只有几个视图能够在旋转设备时旋转到横向.我发现我无法使用,(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)];
}
}
Run Code Online (Sandbox Code Playgroud)
除非您有一个非常基本的应用程序可以拉伸以匹配方向,否则自动调整大小无论如何都不适合您 - 您确实需要为两个方向创建两个单独的视图。
有关自动调整视图大小的帮助,您可以查看本教程:
http://theappleblog.com/2009/04/08/iphone-dev-sessions-how-to-make-an-orientation-aware-clock/
要使用更强大的切换视图的方法,本教程应该可以帮助您:
http://icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning- Between-views/
| 归档时间: |
|
| 查看次数: |
12176 次 |
| 最近记录: |