iPad模态视图不旋转 [英] iPad Modal view not rotating

查看:75
本文介绍了iPad模态视图不旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的应用程序中显示了一个模态视图,其中包含一些用户填写的信息。问题是当旋转设备时,会发生一些动画,但仅限于帧中。表单本身不会旋转。所有自动旋转选项都设置为YES。当用户点击弹出窗口中的字段时,我正在显示它。这让我怀疑它与此有关,但我不确定。这是古怪的,因为如果设备在任一视图中,然后显示模态窗口,它是好的。只有在模态视图中旋转设备时才会发生这种情况。有人知道在旋转设备时可能导致此行为的原因是什么?谢谢!

So I have a modal view displaying in my app that has a little info for the user to fill out. The problem is that when the device is rotated, some animation occurs, but only in the frame. The form itself does not rotate. All the autorotate options are set to YES. I am displaying it when the user clicks on a field in a popover. This makes me suspect it has something to do with that but I am not sure. It is bizzare because if the device is in either view and then the modal window is displayed, it is fine. It only happens when the device is rotated in the modal view. Does anyone have any idea what may be causing this behavior when the device is rotated? Thanks!

这是一个在popover视图控制器中处理的片段:

Here is a snippet that is handled in the popover view controller:

if (currentLevel == 1 && businessOrLocation == 0){
    if(tbsViewController == nil)
        tbsViewController = [[BusinessFilteredViewController alloc] initWithNibName:@"BusinessFilteredView" bundle:[NSBundle mainBundle]];

    NSMutableArray *tempBusiness = [[NSMutableArray alloc] init];
    for (id theKey in appDelegate.groupedBusiness) {
        NSMutableArray *tempArr = [appDelegate.groupedBusiness objectForKey:theKey];
        [tempBusiness addObject:tempArr];
    }

    tbsViewController.businessOrLocation = businessOrLocation;
    tbsViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    tbsViewController.modalTransitionStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:tbsViewController animated:YES];
}


推荐答案

我遇到了这个问题好。根本问题是popover控制器无法呈现模态视图 - 似乎没有正确考虑或设计案例。在我的情况下,解决这个问题很容易。我只是扩展了我的popover托管视图控制器的委托协议。主视图将自身设置为弹出视图的委托,并负责显示和解除用户在弹出框中请求的模态视图。

I ran into this problem as well. The fundamental problem is that popover controllers cannot present modal views—it seems that case wasn’t properly considered or designed for. In my situation, it was easy enough to work around. I just extended the delegate protocol for my popover-hosted view controller. The main view sets itself up as the delegate to the popover view, and takes responsibility for displaying and dismissing the modal views the user requests from within the popover.

因为我已经有一个委托协议,当用户点击完成时,干净地忽略弹出窗口视图,这只是一个很小的延伸,让自动旋转按照我想要的方式工作。以下是一些代码段:

Since I already had a delegate protocol to cleanly dismiss the popover view when the user clicks "done" it was only a small stretch to get autorotation working the way I wanted it to. Here are some snippets:

@protocol InfoViewControllerDelegate <NSObject>

@optional

// Implement this to close the info view once the user clicks done.
- (void)infoViewDidFinish:(InfoViewController *)view;

// Implement this method if the delegate launched us as a popup view and must therefore
// take responsibility for diplaying help.
- (void)infoViewDidRequestHelp:(InfoViewController *)view;

@end

在我的主iPad视图中显示此弹出视图:

And in my main iPad view which presents this popup view:

#pragma mark - InfoViewControllerDelegate methods

- (void)infoViewDidFinish:(InfoViewController *)view {
    [self hideInfo:self];
}

- (void)infoViewDidRequestHelp:(InfoViewController *)view {
    [self hideInfo:self];  // Close the info view first
    HelpViewController *help = [[HelpViewController alloc] init];
    help.delegate = self;
    [self presentModalViewController:help animated:YES];
    [help release];
}

为了让我在启动信息视图之外的情况变得简单弹出视图(例如,在iPhone上,它是一个简单的模态视图),它检查委托是否处理模态子视图,如果没有,则自己处理它们。这样我根本不需要更换iPhone底座控制器,因为自动旋转在那里工作得很好。这是信息视图控制器中的帮助按钮操作,显示我是如何做到的:

To make life simple for cases where I am launching the info view outside of a popup view (for example, on the iPhone, it is a simple modal view), it checks to see if the delegate handles the modal subviews, and if not, handles them itself. That way I didn’t need to change the iPhone base controller at all, since autorotation already worked fine there. Here’s the "Help" button action in the info view controller, showing how I did that:

- (IBAction)help:(id)sender {
    if ([delegate respondsToSelector:@selector(infoViewDidRequestHelp:)]) {
        [delegate infoViewDidRequestHelp:self];
    } else {
        HelpViewController *help = [[HelpViewController alloc] init];
        help.delegate = self;
        [self presentModalViewController:help animated:YES];
        [help release];
    }
}

使用此代码,我的整个界面可以顺利地自动旋转在两个设备上,无论是否涉及弹出视图。

With this code in place, my entire interface autorotates smoothly on both devices, whether or not popup views were involved.

这篇关于iPad模态视图不旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆