Look at the effect

swift: https://github.com/corin8823/Popover
OC: https://github.com/Assuner-Lee/PopoverObjC

Use the sample

pod 'PopoverObjC'
Copy the code
#import "ASViewController.h"
#import <PopoverObjC/ASPopover.h>

@interface ASViewController ()

@property (weak, nonatomic) IBOutlet UIButton *btn;
@property (nonatomic, strong) ASPopover *btnPopover;
@property (nonatomic, strong) ASPopover *itemPopover;

@end

@implementation ASViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self.btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  
  self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"item" style:UIBarButtonItemStylePlain target:self action:@selector(clickItem:)];
}

- (void)didReceiveMemoryWarning {
}
Copy the code

Initialize the Popover

- (ASPopover *)btnPopover {
  if(! _btnPopover) { ASPopoverOption *option = [[ASPopoverOption alloc] init]; option.autoAjustDirection = YES; option.preferedType = ASPopoverTypeDown; option.arrowSize = CGSizeMake(9, 6); option.blackOverlayColor = [UIColor clearColor]; option.popoverColor = [UIColor lightGrayColor]; option.dismissOnBlackOverlayTap = YES; Option. AnimationIn = 0.5; / /... _btnPopover = [[ASPopover alloc] initWithOption:option]; }return _btnPopover;
}


- (ASPopover *)itemPopover {
  if(! _itemPopover) { ASPopoverOption *option = [[ASPopoverOption alloc] init]; option.autoAjustDirection = YES; option.arrowSize = CGSizeMake(10, 6); option.offset = 3; // vertical offset from original show point, default is 0. option.blackOverlayColor = [UIColor clearColor]; option.sideEdge = 7; option.dismissOnBlackOverlayTap = YES; Option. PopoverColor = [[UIColor blackColor] colorWithAlphaComponent: 0.7]; Option. AnimationIn = 0.4; Option. SpringDamping = 0.5; option.initialSpringVelocity = 1; option.overlayBlur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; / /... _itemPopover = [[ASPopover alloc] initWithOption:option]; }return _itemPopover;
}
Copy the code

The popover property can be set in option.

Pop-up bubble

- (void)clickBtn:(id)sender {
  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 50, 40)];
  [self.btnPopover show:view fromView:self.btn];  // in delegate window
}

- (void)clickItem:(id)sender {
  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
  UIView *itemView = [self.navigationItem.rightBarButtonItem valueForKey:@"view"]; // you should use custom view in item;
  if (itemView) {
    [self.itemPopover show:view fromView:itemView]; // above, option has contained offset value; invoke [self show:contentView fromView:fromView inView:keyWindow];
    
    /* other method to show
     
     CGPoint orignPoint = [self.itemPopover orignArrowPointWithView:view fromView:itemView];
     orignPoint.y += 5; // offset inoption has same effect [self.itemPopover show:view atPoint:orignPoint]; * /}}Copy the code

Content View can pop up on a view or a point

Popover interface

#import <UIKit/UIKit.h>
#import "ASPopoverOption.h"

typedef void (^ASPopoverBlock)(void);

@interface ASPopover : UIView

@property (nonatomic, copy) ASPopoverBlock willShowHandler;
@property (nonatomic, copy) ASPopoverBlock willDismissHandler;
@property (nonatomic, copy) ASPopoverBlock didShowHandler;
@property (nonatomic, copy) ASPopoverBlock didDismissHandler;

@property (nonatomic, strong) ASPopoverOption *option;

- (instancetype)initWithOption:(ASPopoverOption *)option;

- (void)dismiss;

- (void)show:(UIView *)contentView fromView:(UIView *)fromView;
- (void)show:(UIView *)contentView fromView:(UIView *)fromView inView:(UIView *)inView;
- (void)show:(UIView *)contentView atPoint:(CGPoint)point;
- (void)show:(UIView *)contentView atPoint:(CGPoint)point inView:(UIView *)inView;

- (CGPoint)originArrowPointWithView:(UIView *)contentView fromView:(UIView *)fromView;
- (CGPoint)arrowPointWithView:(UIView *)contentView fromView:(UIView *)fromView inView:(UIView *)inView popoverType:(ASPopoverType)type;

@end
Copy the code

ContentView: Content to display; FromView: bubbles show from a view; Inview: Bubbles drawn on a view, usually a Delegate window; AtPoint: bubbles show from a point; You can obtain originPoint and offset first.

PopoverOption Interface

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, ASPopoverType) {
  ASPopoverTypeUp = 0,
  ASPopoverTypeDown,
};

@interface ASPopoverOption : NSObject

@property (nonatomic, assign) CGSize arrowSize; // default is (10, 7)
@property (nonatomic, assign) CGFloat offset; // vertical offset from original show point, default is 0.
@property (nonatomic, strong) UIColor *popoverColor;  // contain view color. including arrow.

@property (nonatomic, assign) BOOL autoAjustDirection; //effect just in view not at point; default is YES.
@property (nonatomic, assign) ASPopoverType preferedType; // just effect when autoAjustDirection = YES; default is ASPopoverTypeUp;
@property (nonatomic, assign) ASPopoverType popoverType; // default is ASPopoverTypeUp; not effect when autoAjustDirection = YES;

@property (nonatomic, assign) NSTimeInterval animationIn; // if0, no animation; @ Property (nonatomic, assign) NSTimeInterval animationOut; //if0, no animation; @property (nonatomic, assign) CGFloat springDamping; @property (nonatomic, assign) CGFloat initialSpringVelocity; @property (nonatomic, assign) CGFloat cornerRadius; @property (nonatomic, assign) CGFloat sideEdge; @property (nonatomic, strong) UIColor *blackOverlayColor; // default is black/alpha 0.2, can be clear color. @property (nonatomic, strong) UIBlurEffect *overlayBlur; @property (nonatomic, assign) BOOL dismissOnBlackOverlayTap; // default is YES. @property (nonatomic, assign) BOOL showBlackOverlay; // default is YES. @property (nonatomic, assign) BOOL highlightFromView; @property (nonatomic, assign) CGFloat highlightCornerRadius; @endCopy the code

Thank you for watching