【发布时间】:2011-10-18 12:26:37
【问题描述】:
我有一个UIViewController 子类来处理我对仅横向应用程序的视图。我希望它的视图可以调整大小以自动反映景观尺寸,但似乎没有。但是,子视图可以。
这是复制代码。
@interface MyViewController : UIViewController {
UIView *subview;
}
@implementation MyViewController
- (id)init
{
self = [super init];
if (self) {
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
subview = [[UIView alloc] initWithFrame:self.view.frame];
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:subview];
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
NSLog(@"My view's frame (%f,%f)", self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"Subview's frame (%f,%f)", subview.frame.size.width, subview.frame.size.height);
}
@end
然后……
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.window.rootViewController = [[MyViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
超级简单。然而,在启动时,它会记录:
My view's frame (320.000000,480.000000)
Subview's frame (480.000000,320.000000)
子视图已正确调整大小,但父视图仍有纵向框架。
如何调整顶层视图的大小以适应横向模式?
【问题讨论】:
标签: ios uiview uiviewcontroller