美文网首页
UIPopoverPresentationController弹

UIPopoverPresentationController弹

作者: 文子飞_ | 来源:发表于2021-06-30 15:29 被阅读0次
UIPopoverPresentationController弹出菜单
- (void)popoverPresentationController {
CGRect moreButtonFrame = [self.moreButton convertRect: self.moreButton.bounds toView:self.viewController.view];
    
    CGFloat bubbleListViewHeight = (array.count * 40);
    CGFloat bubbleListViewWidth = 120;

    //用来判断气泡能不能显示完全,如果显示不完全就显示在上方
    BOOL directionDown = (CGRectGetMaxY(moreButtonFrame) + bubbleListViewHeight > CGRectGetHeight(self.viewController.view.frame));
    
    if (directionDown) {
        self.bubbleListView.frame = CGRectMake(0, 0, bubbleListViewWidth, bubbleListViewHeight);

    }else {
        self.bubbleListView.frame = CGRectMake(0, 15, bubbleListViewWidth, bubbleListViewHeight);

    }
    self.contentVC.preferredContentSize = CGSizeMake(bubbleListViewWidth, CGRectGetHeight(self.bubbleListView.frame));
    self.contentVC.view.backgroundColor = [UIColor clearColor];
    self.contentVC.modalPresentationStyle = UIModalPresentationPopover;
    [self.contentVC.view addSubview:self.bubbleListView];
    
    UIPopoverPresentationController *popover = self.contentVC.popoverPresentationController;
    popover.backgroundColor = [[UIColor colorWithHexString:@"#28313A"] colorWithAlphaComponent:0.9];
    popover.delegate = self;
    popover.sourceView = self.moreButton;

    
    popover.sourceRect = CGRectMake(-3, 0, CGRectGetWidth(self.moreButton.frame), CGRectGetHeight(self.moreButton.frame));
    
    if (directionDown) {
        popover.permittedArrowDirections = UIPopoverArrowDirectionDown;

    }else {
        
        popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
    }


    if (self.viewController) {
        [self.viewController presentViewController:self.contentVC animated:YES completion:nil];//推出popover
    }
}

-(void)imageClick:(ImageTextView *)imageTextView {
    
    if (self.clickBlcok) {
        self.clickBlcok(self.model, imageTextView.tag);
    }
    [self.contentVC dismissViewControllerAnimated:YES completion:nil];

}

相关文章

网友评论

      本文标题:UIPopoverPresentationController弹

      本文链接:https://www.haomeiwen.com/subject/vjyrultx.html