UIPopoverPresentationController彈出菜單

UIPopoverPresentationController彈出菜單
- (void)popoverPresentationController {
CGRect moreButtonFrame = [self.moreButton convertRect: self.moreButton.bounds toView:self.viewController.view];
    
    CGFloat bubbleListViewHeight = (array.count * 40);
    CGFloat bubbleListViewWidth = 120;

    //用來(lái)判斷氣泡能不能顯示完全,如果顯示不完全就顯示在上方
    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];

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天實(shí)現(xiàn)一個(gè)小功能, 仿微信、QQ 那樣的彈出菜單. 在之前如果想要在iphone上實(shí)現(xiàn)popover的效果需要自...
    樹(shù)根曰閱讀 2,746評(píng)論 0 3
  • 最近項(xiàng)目中使用到pop形勢(shì)的一個(gè)菜單視圖,像微信、QQ右上角的點(diǎn)擊"+"展開(kāi)的一樣,就自己造了個(gè)輪子方便以后的使用...
    我是帥帥唐僧閱讀 658評(píng)論 0 1
  • 一、彈出菜單 制作一個(gè)可以彈出的菜單,具體直接看效果吧~ 2,為按鈕設(shè)置樣式,在values文件中 3,添加動(dòng)畫(huà)(...
    颵麏閱讀 1,405評(píng)論 0 4
  • 表情是什么,我認(rèn)為表情就是表現(xiàn)出來(lái)的情緒。表情可以傳達(dá)很多信息。高興了當(dāng)然就笑了,難過(guò)就哭了。兩者是相互影響密不可...
    Persistenc_6aea閱讀 129,685評(píng)論 2 7
  • 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險(xiǎn)厭惡者,不喜歡去冒險(xiǎn),但是人生放棄了冒險(xiǎn),也就放棄了無(wú)數(shù)的可能。 ...
    yichen大刀閱讀 7,874評(píng)論 0 4

友情鏈接更多精彩內(nèi)容