【问题标题】:How can I get to dim everything except for the sourceView when presenting UIPopoverViewController?在呈现 UIPopoverViewController 时,如何使除 sourceView 之外的所有内容变暗?
【发布时间】:2019-08-29 08:56:58
【问题描述】:

我正在开发一个类似于 WhatsApp 的聊天应用程序。当用户长按消息时,会显示带有选项的弹出框。除了弹出框和弹出框的 sourceView 之外,我想调暗背景中的所有内容。像这样:

我试过了,但是所有的背景都变暗了:

- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController {
    [[popoverPresentationController containerView] setBackgroundColor:[UIColor colorWithWhite:0 alpha:.72]];

}

【问题讨论】:

    标签: ios objective-c iphone uipopovercontroller


    【解决方案1】:

    Javad

    您可以在演示视图中全屏添加空白。设置黑色背景颜色和 alpha 0.5 会产生暗淡的效果。

    谢谢

    【讨论】:

    • 不会让所有东西都变暗,包括 sourceView 吗?
    • 是的,因为空白视图独立于源视图
    • 好的,但是我想保持源视图不变,即不变暗,只有它的周围,请看图片。
    • 我相信我需要将源视图添加到背景视图中:/
    【解决方案2】:

    我设法通过重新创建一个单元格并将其添加到弹出容器视图中来做到这一点:

    - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController {
        [[popoverPresentationController containerView] setBackgroundColor:[UIColor colorWithWhite:0 alpha:.72]];
    
        MessageCellNode *messageNode = [[MessageCellNode alloc] init];
    
        UICollectionViewLayoutAttributes *attributes = [[self.collectionNode view] layoutAttributesForItemAtIndexPath:indexPathToSelect];
        CGRect cellRect = attributes.frame;
    
        CGRect rect = [[[self collectionNode] view] convertRect:cellRect toView:[[UIApplication sharedApplication] keyWindow]];
    
        [messageNode setFrame: rect];
    
        [[popoverPresentationController containerView]addSubview:[messageNode view]];
    }
    

    结果:

    【讨论】:

      猜你喜欢
      • 2017-06-13
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      相关资源
      最近更新 更多