效果图如下所示:
swift: https://github.com/corin8823/popover oc: https://github.com/assuner-lee/popoverobjc
使用示例
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
pod 'popoverobjc'
#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 {
}
|
初始化popover
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
- (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里设置。
弹出气泡
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
- (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
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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
|
contentview: 要显示的内容; fromview: 气泡从某一个视图上show; inview: 气泡绘制在某一个视图上,一般为delegate window; atpoint: 气泡从某一点上show; 可先获取originpoint, 偏移;
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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气泡效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc的支持!
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 23
-
2025-05-25 23
-
2025-05-27 55
-
2025-06-04 38
-
2025-05-25 100
热门评论


