iOS黑科技【動(dòng)畫特效篇】第五期
本期的控件也是實(shí)用性非常高的一款彈窗控件,系統(tǒng)雖然本身自帶了一個(gè)UIAlertController键痛,但是效果一般觅彰,每次集成需要寫很長(zhǎng)一段施蜜,影響了代碼的整潔和美觀曲初,于是我們自己動(dòng)手做一個(gè)体谒。
先看看效果吧
XMActionSheetpic.png
XMActionSheet.gif
免費(fèi)贈(zèng)送git地址:
https://github.com/XMDashen/XMActionSheet.git
使用介紹:
懶人集成方法,核心代碼只需兩句复斥,第一步創(chuàng)建营密,第二步展示,簡(jiǎn)潔美觀大方
系統(tǒng)風(fēng)格彈窗彈窗
NSArray *titleArray=@[@"支付寶",@"微信",@"花唄"];
XMActionSheet *sysSheet=[[XMActionSheet alloc] initWithTitles:titleArray WithActionBlock:^(NSInteger selectIndex) {
if (selectIndex==0) {
NSLog(@"支付寶");
}
if (selectIndex==1) {
NSLog(@"微信");
}
if (selectIndex==2) {
NSLog(@"花唄");
}
}];
[sysSheet showSheetOnWindow];
自定義風(fēng)格彈窗
XMActionSheet *sheet=[[XMActionSheet alloc] initWithTitles:@[@"支付寶",@"微信",@"花唄"] LeftImagesNameArray:@[@"ic_alipay@2x",@"ic_wx@2x",@"ic_charge@2x"] sheetDescription:@"選擇支付方式" WithActionBlock:^(NSInteger selectIndex) {
if (selectIndex==0) {
NSLog(@"支付寶");
}
if (selectIndex==1) {
NSLog(@"微信");
}
if (selectIndex==2) {
NSLog(@"花唄");
}
}];
[sheet showSheetOnWindow];
需要更多自定義請(qǐng)給這些屬性賦值
/*sheet選項(xiàng)標(biāo)題*/
@property (nonatomic,strong) NSArray *titlesArray;
/*sheet選項(xiàng)圖標(biāo)*/
@property (nonatomic,strong) NSArray<NSString *> *imagesArray;
/*是否顯示右側(cè)箭頭*/
@property (nonatomic,assign) BOOL isShowArrow;
/*sheet頂部描述*/
@property (nonatomic,strong) NSString *sheetDesciption;
/*sheet風(fēng)格*/
@property (nonatomic,assign) XMSheetStyle sheetStyle;
/*取消按鈕顏色*/
@property (nonatomic,strong) UIColor *cancelBtnColor;
/*sheet選項(xiàng)標(biāo)題顏色*/
@property (nonatomic,strong) NSArray<UIColor *> *titlesColorArray;
原理解析:
實(shí)現(xiàn)原理很簡(jiǎn)單:背景層+tableView表單層+邏輯+動(dòng)畫過度
代碼也不復(fù)雜,處理好細(xì)節(jié)就可以了
系統(tǒng)簡(jiǎn)單動(dòng)畫過度效果就不錯(cuò)了
[UIView animateWithDuration:0.2 animations:^{
self.shelterView.alpha=0.5;
self.tableView.frame=CGRectMake(tableViewX, tableViewY, tableViewW, tableViewH);
} completion:^(BOOL finished) {
}];
可用貝塞爾曲線切割指定圓角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cellBounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cellBounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
這一期就到這里了目锭,親們有什么意見和問題記得及時(shí)反饋哦,喜歡的話點(diǎn)個(gè)關(guān)注給個(gè)贊就可以了纷捞,千萬不要打賞哦(づ ̄3 ̄)づ╭?~
我們下期再會(huì)