簡體   English   中英

介紹UIPopoverViewController時,如何使除sourceView之外的所有內容變暗?

[英]How can I get to dim everything except for the sourceView when presenting UIPopoverViewController?

我正在開發類似於WhatsApp的聊天應用程序。 當用戶長按消息時,將顯示帶有選項的彈出窗口。 我想使除彈出框和彈出框的sourceView之外的所有背景變暗。 像這樣: 在此處輸入圖片說明

我試過了,但是所有背景都變暗了:

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

}

賈瓦德

您可以在演示視圖中全屏添加空白。 設置黑色背景色和alpha 0.5,將創建暗淡效果。

謝謝

我設法通過重新創建單元格並將其添加到popover containerView來做到這一點:

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

結果: 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM