简体   繁体   English

iPad模式视图未旋转

[英]iPad Modal view not rotating

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! 谢谢!

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];
}

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. 我刚刚扩展了我的由Popover托管的视图控制器的委托协议。 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

And in my main iPad view which presents this popup view: 在我的主要iPad视图中,它显示了此弹出视图:

#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];
}

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. 为了简化我在弹出视图之外启动信息视图的情况(例如,在iPhone上,它是一个简单的模式视图),它会检查委托是否处理模式子视图,如果不是,自己处理。 That way I didn't need to change the iPhone base controller at all, since autorotation already worked fine there. 这样,我根本不需要更改iPhone基本控制器,因为自动旋转已经可以正常工作了。 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. 有了此代码,无论是否涉及弹出视图,我的整个界面都可以在两个设备上流畅地自动旋转。

Just so i understand correctly... You are displaying a popover and inside that popover if the user taps a certain element then you are displaying a full screen modal view controller? 只要这样我就可以正确理解...您正在显示一个弹出窗口,并且在该弹出窗口中,如果用户点击某个元素,那么您将显示一个全屏模式视图控制器? Vie never tried that before and it seems odd for two reasons. Vie以前从未尝试过,而且似乎有两个原因。

First it seems jarring to the user in my opinion. 首先,在我看来,这似乎给用户带来了不适。 The popover gives you a nice, integrated UI and the modal takes you away. 弹出窗口为您提供了一个不错的集成UI,而模式使您无法使用。

More importantly though, your popover view controller doesn't really have authority over the whole screen so presenting a full screen modal from a popover just seems inherently wrong. 但是,更重要的是,您的Popover视图控制器实际上并不具有对整个屏幕的权限,因此,从Popover呈现全屏模式似乎是天生的错误。

I would suggest you display a nav controller in the popover controller and instead of presenting the new view controller modally over the whole screen just push it on to the nav controller in the popover and keep the user inside the popover. 我建议您在弹出窗口控制器中显示一个导航控制器,而不是在整个屏幕上模态呈现新的视图控制器,只需将其推入弹出窗口中的导航控制器,并将用户保持在弹出窗口内即可。

If that doesn't really work for you, then I would suggest reviewing your UI needs and redesigning the layout. 如果那确实不适合您,那么我建议您检查一下UI需求并重新设计布局。

I am guessing that you implemented - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation in BusinessFilteredViewController and returns YES 我猜你已经实现了- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationBusinessFilteredViewController - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation并返回YES

Could you check that you add more than 1 subviews to application window . 您可以检查是否向应用程序窗口添加了1个以上的子视图。 If so, try to create container UIViewController for all viewControllers that you want to add to window. 如果是这样,请尝试为要添加到窗口的所有viewController创建容器UIViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM