我正在尝试使用我的应用程序解决一个非常令人沮丧的问题 - 在研究它时我可能在iOS中发现了一个错误:
旋转iPad时,视图会旋转,但它的框架不会改变.我正在运行一个计时器,每秒打印出我的视图的宽度和高度,虽然我可以看到视图在视觉上旋转,但框架仍然是"768x1024",无论如何.
来自Apple的文档:
当用户界面旋转时,将调整窗口大小以匹配新方向.窗口调整其根视图控制器的框架以匹配新大小,并且此大小依次沿视图层次结构传播到其他视图.
这正是未发生的事情,它给我带来了各种各样的麻烦.有谁知道如何修复旋转,以便框架改变?
重现步骤:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height);
// Add a label to confirm orientation
UILabel *orientationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,30)];
orientationLabel.text = @"Top Left";
[self.window.rootViewController.view addSubview: orientationLabel];
[NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(testScale) userInfo:nil repeats:YES];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void) testScale {
NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height);
}
| 归档时间: |
|
| 查看次数: |
5144 次 |
| 最近记录: |