shouldAutorotateToInterfaceOrientation 被多次调用 - 这正常吗?
我的分割视图控制器代码:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
.