gpt4 book ai didi

iOS 6 旋转错误 : Window and Root View Controller frame does not change despite rotation

转载 作者:可可西里 更新时间:2023-11-01 04:53:59 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
“Incorrect” frame / window size after re-orientation in iPhone

我正在尝试用我的应用程序解决一个非常令人沮丧的问题 - 在研究它时我可能发现了 iOS 中的一个错误:

当您旋转 iPad 时, View 会旋转,但它的框架不会改变。我正在运行一个计时器,它每秒打印出我的 View 的宽度和高度,虽然我可以看到 View 在视觉上旋转,但无论如何框架仍然是“768x1024”。

来自 Apple 的文档:

When the user interface rotates, the window is resized to match the new orientation. The window adjusts the frame of its root view controller to match the new size, and this size in turn is propagated down the view hierarchy to other views.

这正是没有发生的事情,它给我带来了各种各样的麻烦。有谁知道如何修复旋转以便框架发生变化?

重现步骤:

  1. 创建一个新的空项目
  2. 添加 Backbone UIViewController 作为 Root View
  3. 设置一个计时器来打印出 Root View Controller 的框架宽度和高度
  4. 运行您的应用,并旋转它。这是我正在测试的代码:
- (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);}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com