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