使用ModalPresentationStyle的Popover不在iOS 7 iPad中居中 [英] Popover with ModalPresentationStyle is not centered in iOS 7 iPad

查看:121
本文介绍了使用ModalPresentationStyle的Popover不在iOS 7 iPad中居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有iOS 7的问题似乎是一个错误或我只是不做正确的事情。我有modalViewController,它在iPad上使用ModalPresentationStyle显示为popover。它不是标准尺寸,自定义尺寸。
以下是代码:

I have a problem with iOS 7 that seems to be a bug or I just don't do something right. I have modalViewController that appears as a popover on iPad with ModalPresentationStyle. And it is not standard size, custom sized. Here is the code:

myViewController *myVC = [[myViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myVC];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[nav setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];
[self presentViewController:nav animated:YES completion:nil];
nav.view.superview.bounds = CGRectMake(0, 0, 320, 465);

这在iOS 6中都运行良好,但在iOS 7中并没有集中。
但是如果我将ModalTransitionStyle设置为UIModalTransitionStyleCrossDissolve,它可以正常工作。但只有在这种模式下。
也许有人偶然发现了这个并且知道如何修复它?我不是解散效果的忠实粉丝。
谢谢。

It's all working fine in iOS 6, but in iOS 7 it's not centered. But if I set ModalTransitionStyle to UIModalTransitionStyleCrossDissolve it works fine. But only in this mode. Maybe someone stumbled on this one too and know how to fix it? I'm not a big fan of dissolve effect. Thank you.

推荐答案

我有一个方法,其中旧的自定义模态演示文稿样式 fromsheet 适用于 iOS< = 7 ,但您可以设置自定义高度和宽度

I have a method where the old custom modal presentation style fromsheet works with iOS <=7 although you might set custom height and width.

请注意,此方法未来可能无法在任何较新版本中使用

- (void) hackModalSheetSize:(CGSize) aSize ofVC:(UIViewController *) aController;
{

    void (^formSheetBlock) (void) = ^{
        int preferredWidth = aSize.width;
        int preferredHeight = aSize.height;

        CGRect frame = CGRectMake((int) 1024/2 - preferredWidth/2,
                                  (int) 768/2 - preferredHeight/2,
                                  preferredWidth, preferredHeight);
        aController.view.superview.frame = frame;
        if([aController respondsToSelector:@selector(edgesForExtendedLayout)]) { //ios7
            aController.view.superview.backgroundColor = [UIColor clearColor];
        } else { // < ios7
            UIImageView *backgroundView = [aController.view.superview.subviews objectAtIndex:0];
            [backgroundView removeFromSuperview];
        }
    };

    //on ios < 7 the animation would be not as smooth as on the older versions so do it immediately
    if(![self respondsToSelector:@selector(edgesForExtendedLayout)]) {
        formSheetBlock();
        return;
    }

    double delayInSeconds = .05;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        formSheetBlock();
    });
}

这篇关于使用ModalPresentationStyle的Popover不在iOS 7 iPad中居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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