最近閑暇時間造了個輪子:
LKPopover
首先它是一個輕量級的popover。使用是非常方便的只需要一步就可以使用它,同時它的功能也非常強(qiáng)大,它就好比是一個容器把需要的內(nèi)容添加進(jìn)去就可以顯示出來。
使用
eg:

demo.gif
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
image.image = [UIImage imageNamed:@"222"];
LKPopover *popover = [LKPopover popover];
[popover showAtView:sender withContentView:image];
UIButton *btn = [[UIButton alloc] initWithFrame:(CGRect){CGPointZero, CGSizeMake(100, 40)}];
[btn setTitle:@"I an btn" forState:UIControlStateNormal];btn.backgroundColor = [UIColor redColor];
LKPopover *lk = [LKPopover popover];CGPoint point = CGPointMake(CGRectGetMidX(senderBtn.frame), CGRectGetMidY(senderBtn.frame));
[lk showAtPoint:point popoverPostion:LKPopoverPositionTypeUp withContentView:btn inView:self.view];
UIView *titleView = self.navigationItem.titleView;CGPoint startPoint =CGPointMake(CGRectGetMidX(titleView.frame), CGRectGetMaxY(titleView.frame) + 20);
self.lkPopover.backgroundColor = [UIColor redColor];
self.lkPopover.contentInset = UIEdgeInsetsMake(5, 10, 5, 10);
self.lkPopover.maskType = LKPopoverMaskTypeNone;[self.lkPopover showAtPoint:startPointpopoverPostion:LKPopoverPositionTypeDownwithContentView:self.tableViewinView:self.tabBarController.view];
__weak typeof (self) weakSelf = self;
self.lkPopover.didDismssHandler = ^{[weakSelf bounceTargetView:titleView];};
用法非常簡單沒什么可講的支持的方法屬性也特別多,注釋講的也非常清楚。
下面說說干活
-
LKPopover支持懶顯示
什么意思類:使用時不需要判斷箭頭顯示位置,它會根據(jù)底部視圖大小自動判斷距離,通過距離長度判斷箭頭位置。
這里用到了坐標(biāo)轉(zhuǎn)換有點(diǎn)繞來個傳送門UIView中坐標(biāo)轉(zhuǎn)換
-
設(shè)計(jì)思路
設(shè)計(jì)這個輪子時候考慮到容器與顯示視圖解耦問題,決定LKPopover的大小是由顯示視圖來控制。
這樣的寫法當(dāng)然是有好處的:
```
- (instancetype)initWithFrame:(CGRect)frame{
//CGRectZero 1>設(shè)計(jì)時考慮到根據(jù)顯示的內(nèi)容尺度畫出mask
// 2>設(shè)置CGRectZero 創(chuàng)建時不會調(diào)用drawRect,保證設(shè)置屬性有效果,也有點(diǎn)考慮性能防止反復(fù)繪制
// 3>先判斷箭頭位置和容器大小,在繪制容器
if (self = [super initWithFrame:CGRectZero]) {
[self propertyInit];
}
return self;
}
##聯(lián)系我
歡迎提建議,可以直接提issue。
謝謝支持(順便star)。
###本人早前的另一個輪子github:[LKFMDB](https://github.com/HectorLiuk/LKFMDB)
簡書地址[對FMDB面向?qū)ο蠓庋b
](http://www.itdecent.cn/p/811e87ac844e)