PS:最近項(xiàng)目需要,微信樣式的底部選擇彈框,自定義的帶有簡(jiǎn)單動(dòng)畫樣式的彈窗以及多項(xiàng)選擇功能.
最近將這三個(gè)需求進(jìn)行了一下簡(jiǎn)單的封裝,基本上兩行代碼就可以滿足以上需求.
示例GIF

用法如下:
//微信樣式底部彈窗示例代碼如下:
- (IBAction)clickStyle1Button:(UIButton *)sender {
__weak typeof(self) weakSelf = self;
//選擇數(shù)組
NSArray *dataArray = [NSArray arrayWithObjects:@"小視頻", @"拍照",@"從手機(jī)相冊(cè)選擇",@"取消",nil];
CCPActionSheetView *actionSheetView = [[CCPActionSheetView alloc]initWithActionSheetArray:dataArray];
//點(diǎn)擊完成后的回調(diào)
[actionSheetView cellDidSelectBlock:^(NSString *indexString, NSInteger index) {
weakSelf.selectedContentLabel.text = [NSString stringWithFormat:@"%ld----%@",(long)index,indexString];
}];
}
//帶有動(dòng)畫效果的彈窗示例代碼如下
- (IBAction)clickStyle2Button:(UIButton *)sender {
//自定義的彈窗view
UIImageView *testView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
testView.userInteractionEnabled = YES;
testView.image = [UIImage imageNamed:@"image0"];
CCPActionSheetView *alertview = [[CCPActionSheetView alloc] initWithAlertView:testView];
//動(dòng)畫樣式
alertview.viewAnimateStyle = ViewAnimateScale;
}
//多項(xiàng)選擇示例代碼如下:
- (IBAction)clickMakeChoiceBtn:(UIButton *)sender {
//測(cè)試數(shù)據(jù)源數(shù)組
NSArray *dataArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21", nil];
//ClickSureBtnBlock —> 確定按鈕的回調(diào),將拼接好的字符串,以及選擇成功的數(shù)組回調(diào)到當(dāng)前VC
//ClickCancelBtnBlock —> 取消按鈕的回調(diào)
CCPMultipleChoiceView *ChoiceView = [[CCPMultipleChoiceView alloc] initWithDataArr:dataArray andClickSureBtnBlock:^(NSString *combinedString, NSArray *backArray) {
self.choiceResultLabel.text = combinedString;
NSLog(@"%@",backArray);
} andClickCancelBtnBlock:^{
}];
//測(cè)試已經(jīng)選中的數(shù)據(jù)源數(shù)組
如果不需要進(jìn)入選擇視圖時(shí)顯示已經(jīng)選擇的選項(xiàng)則? 設(shè)置? ? ? ChoiceView.selectedArray = nil;
//如果需要進(jìn)入選擇視圖時(shí)顯示已經(jīng)選擇的選項(xiàng) 則設(shè)置已經(jīng)選中的數(shù)據(jù)源數(shù)組
//@[@"1",@"3",@"10",@"0",@"20"]; 為對(duì)應(yīng)的選中數(shù)據(jù)的下標(biāo)
ChoiceView.selectedArray = @[@"1",@"3",@"10",@"0",@"20"];
}
希望在為你帶來(lái)些許幫助的同時(shí), star 一下該demo,感謝你的閱讀.