ios点击大头针气泡不弹出_简单好用可任意定制的iOS Popover气泡效果

效果图如下所示:

使用示例

pod 'PopoverObjC'

#import "ASViewController.h"

#import

@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 {

}

初始化Popover

- (ASPopover *)btnPopover {

if (!_btnPopover) {

ASPopoverOption *option = [[ASPopoverOption alloc] init];

option.popoverType = ASPopoverTypeUp;

option.autoAjustDirection = NO;

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 = NO;

option.arrowSize = CGSizeMake(10, 6);

option.blackOverlayColor = [UIColor clearColor];

option.sideEdge = 7;

option.dismissOnBlackOverlayTap = YES;

option.popoverColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];

option.autoAjustDirection = YES;

option.animationIn = 0.4;

option.springDamping = 0.5;

option.initialSpringVelocity = 1;

option.overlayBlur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

//...

_itemPopover = [[ASPopover alloc] initWithOption:option];

}

return _itemPopover;

}

popover的属性可在option里设置。

弹出气泡

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

CGPoint originPoint = [self.itemPopover originArrowPointWithView:view fromView:itemView];

originPoint.y += 5;

[self.itemPopover show:view atPoint:originPoint];

}

}

@end

可在某一个视图或某一个point上弹出内容view

Popover interface

#import

#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

contentView: 要显示的内容; fromView: 气泡从某一个视图上show; inview: 气泡绘制在某一个视图上,一般为delegate window; atPoint: 气泡从某一点上show; 可先获取originPoint, 偏移;

PopoverOption Interface

typedef NS_ENUM(NSInteger, ASPopoverType) {

ASPopoverTypeUp = 0,

ASPopoverTypeDown,

};

@interface ASPopoverOption : NSObject

@property (nonatomic, assign) CGSize arrowSize;

@property (nonatomic, assign) NSTimeInterval animationIn; // if 0, no animation

@property (nonatomic, assign) NSTimeInterval animationOut;

@property (nonatomic, assign) CGFloat cornerRadius;

@property (nonatomic, assign) CGFloat sideEdge;

@property (nonatomic, strong) UIColor *blackOverlayColor;

@property (nonatomic, strong) UIBlurEffect *overlayBlur;

@property (nonatomic, strong) UIColor *popoverColor;

@property (nonatomic, assign) BOOL dismissOnBlackOverlayTap;

@property (nonatomic, assign) BOOL showBlackOverlay;

@property (nonatomic, assign) CGFloat springDamping;

@property (nonatomic, assign) CGFloat initialSpringVelocity;

@property (nonatomic, assign) ASPopoverType popoverType;

@property (nonatomic, assign) BOOL highlightFromView;

@property (nonatomic, assign) CGFloat highlightCornerRadius;

@property (nonatomic, assign) BOOL autoAjustDirection; // down preferred, effect just in view not at point

@end

总结

以上所述是小编给大家介绍的简单好用可任意定制的iOS Popover气泡效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家的支持!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值