didRotateFromInterfaceOrientation 旋转时未触发?
我遇到了 didRotateFromInterfaceOrientation 方法无法同时触发的问题我的视图控制器子类。
我有一个 iPad 应用程序,以 UISplitViewController 作为主视图。在细节方面,我使用“隐藏”(无工具栏、导航栏)导航控制器来进行延迟视图切换。我想要捕获 didRotateFromInterfaceOrientation 的 ViewController 位于 navcontroller 层次结构的两层深处。 (这些都不会产生影响,但我包含此信息,以防出现我不知道的某些特殊情况)
我有:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
NSLog(@"Rotate Go!");
}
视图旋转得很好,但 didRotateFromInterfaceOrientation 永远不会触发。
知道我缺少什么吗?
Possible Duplicate:
ViewController not responding to didRotateFromInterfaceOrientation
I'm having trouble with the didRotateFromInterfaceOrientation method not firing in one of my viewcontroller subclasses.
I have an iPad app w/ UISplitViewController as the main view. On the Detail side, I'm using a "hidden" (no toolbar,navbar) navigation controller for lazy view switching. The ViewController I'm wanting to catch didRotateFromInterfaceOrientation on is two levels deep in the navcontroller hierarchy. (None of this should make a difference, but I'm including this info in case there's some particular case that I don't know about)
I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
NSLog(@"Rotate Go!");
}
The view rotates just fine, but didRotateFromInterfaceOrientation never fires.
Any idea what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的 UIViewController 是某个根视图中的子控制器,那么默认情况下 IB 不会将其作为子控制器添加到根控制器中。解决这个问题最简单的方法是修改你的根控制器:
这应该可以解决问题。现在您的子控制器将接收:
和
消息。
If your UIViewController is a child in some root view then IB does not add it as a child controller to the root controller by default. The easiest way to address this is to modify your root controller:
This should do the trick. Now your child controller will be receiving both:
and
messages.
好吧,我从来没有弄清楚为什么事件没有触发,但我确实找到了一个解决方法:
在两个
UISplitViewController
委托方法中,splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
和 splitViewController:willShowViewController:invalidatingBarButtonItem:,我正在检测我的视图是否可见,然后在这里执行我的旋转逻辑。Well, I never did figure out why the events were not firing, but I did figure out a workaround:
In the two
UISplitViewController
delegate methods,splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
andsplitViewController:willShowViewController:invalidatingBarButtonItem:
, I'm detecting whether or not my view is visible, and then doing my rotation logic here.