7

UIPopoverController を使用して、次のように iPad iOS7 でビューをポップアップします。

    if (!self.popover) {
        UIViewController *popupVC = [[UIViewController alloc] init];
        [popupVC.view addSubview:thePopupView];
        popupVC.preferredContentSize = CGSizeMake(240, 140);
        self.popover = [[UIPopoverController alloc] initWithContentViewController:popupVC];
        self.popover.delegate = self;
    }


    [self.popover presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

ただし、ポップオーバーがアクティブになると、画面が暗くなりますが、この効果は iOS6 の他のビューには影響しません。

この問題を克服するにはどうすればよいですか?ありがとう!

4

2 に答える 2

4

ポップオーバーの下に挿入された薄暗いビューを意味する場合、回避策は 1 つだけです - カスタムを使用しますpopoverBackgroundViewClass

複雑ですが、思ったほど複雑ではありません。

于 2013-09-19T15:15:28.730 に答える
2

もう 1 つの方法は、ポップオーバー ビュー スタックをトラバースし、調光ビューを手動で削除することです。UIPopoverControllerサブクラスで次のように示します。

@property (nonatomic, assign) BOOL showsDimmingView;

....

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
           permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
                           animated:(BOOL)animated
{
    [super presentPopoverFromBarButtonItem:item
                  permittedArrowDirections:arrowDirections
                                  animated:animated];

    if (!_showsDimmingView) {
        [self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
    }
}

- (void)presentPopoverFromRect:(CGRect)rect
                        inView:(UIView *)view
      permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
                      animated:(BOOL)animated
{
    [super presentPopoverFromRect:rect
                           inView:view
         permittedArrowDirections:arrowDirections
                         animated:animated];

    if (!_showsDimmingView) {
        [self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
    }
}

- (void)removeDimmingView:(UIView *)subview
{
    for (UIView *sv in subview.subviews) {

        if (sv.alpha == 0.15f && [sv isKindOfClass:NSClassFromString(@"_UIPopoverViewBackgroundComponentView")]) {
            sv.alpha = 0.f;
        }

        const CGFloat *components = CGColorGetComponents(sv.backgroundColor.CGColor);
        if (sv.backgroundColor && (components[1] == 0.15f || sv.alpha == 0.15f)) {
            [sv removeFromSuperview];
        }

        [self removeDimmingView:sv];
    }
}
于 2013-11-14T19:10:53.707 に答える