shouldAutorotateToInterfaceOrientation 被多次调用 - 这正常吗?

发布于 2024-12-11 11:45:28 字数 1708 浏览 0 评论 0原文

我的分割视图控制器代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    LeftViewController *hvc = [[[LeftViewController alloc] initWithNibName:nil bundle:nil] autorelease];    
    DetailViewController *dvc = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];
    UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:hvc] autorelease];
    UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:dvc] autorelease];
    UISplitViewController *svc= [[[UISplitViewController alloc] init] autorelease];
    [svc setViewControllers:[NSArray arrayWithObjects:rootNav, detailNav, nil]];
    svc.delegate = dvc;
    [window setRootViewController:svc];
    [self.window makeKeyAndVisible];
    return YES;
}

DetailViewController.m 和 LeftViewController.m 都包含

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"should rotate asked to detailviewcontroller");
    return YES;
}

在 iPad 模拟器上,当应用程序刚刚启动时,我可以看到对 shouldAutorotateToInterfaceOrientation 的许多调用

should rotate asked to detailviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller
...
should rotate asked to leftviewcontroller   // these two lines
should rotate asked to detailviewcontroller // are repeated 13 times
...
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller

这背后的原因可能是什么?我必须提到我不会改变模拟器的方向

My split view controller code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    LeftViewController *hvc = [[[LeftViewController alloc] initWithNibName:nil bundle:nil] autorelease];    
    DetailViewController *dvc = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];
    UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:hvc] autorelease];
    UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:dvc] autorelease];
    UISplitViewController *svc= [[[UISplitViewController alloc] init] autorelease];
    [svc setViewControllers:[NSArray arrayWithObjects:rootNav, detailNav, nil]];
    svc.delegate = dvc;
    [window setRootViewController:svc];
    [self.window makeKeyAndVisible];
    return YES;
}

DetailViewController.m and LeftViewController.m both contain

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"should rotate asked to detailviewcontroller");
    return YES;
}

On the iPad simulator, I can see these many calls to shouldAutorotateToInterfaceOrientation when the app just gets launched

should rotate asked to detailviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller
...
should rotate asked to leftviewcontroller   // these two lines
should rotate asked to detailviewcontroller // are repeated 13 times
...
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller

What could be the reason behind this? I must mention I am not changing orientation of the simulator

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶 2024-12-18 11:45:28

shouldAutorotateToInterfaceOrientation 旨在检查您的视图是否支持特定方向。

这并不一定意味着您的设备正在移动/旋转。

您不必担心导致外部实体多次查询视图控制器的实现细节,只需为您的视图返回适当的值即可。

如果您对检测设备旋转感兴趣,您可能会决定依赖 UIDeviceOrientationDidChangeNotification

shouldAutorotateToInterfaceOrientation is meant to check whether your view supports a specific orientation or not.

It does not necessarily mean that your device is moving / being rotated.

You shouldn't worry about the implementation details that lead external entities to query your view controller multiple times, and just return the appropriate value for your views.

If you're interested in detecting device rotations, you might decide to rely on UIDeviceOrientationDidChangeNotification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文