didRotateFromInterfaceOrientation 旋转时未触发?

发布于 2024-11-03 13:39:48 字数 902 浏览 1 评论 0原文

可能的重复:
ViewController 未响应 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 技术交流群。

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

发布评论

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

评论(2

中二柚 2024-11-10 13:39:48

如果您的 UIViewController 是某个根视图中的子控制器,那么默认情况下 IB 不会将其作为子控制器添加到根控制器中。解决这个问题最简单的方法是修改你的根控制器:

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self addChildViewController:(UIViewController*) self.yourChildController];
}  

这应该可以解决问题。现在您的子控制器将接收:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

消息。

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:

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self addChildViewController:(UIViewController*) self.yourChildController];
}  

This should do the trick. Now your child controller will be receiving both:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

and

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

messages.

ㄖ落Θ余辉 2024-11-10 13:39:48

好吧,我从来没有弄清楚为什么事件没有触发,但我确实找到了一个解决方法:

在两个 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: and splitViewController:willShowViewController:invalidatingBarButtonItem:, I'm detecting whether or not my view is visible, and then doing my rotation logic here.

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