国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現帶遮罩的彈出選項卡

2020-07-26 01:29:27
字體:
來源:轉載
供稿:網友

在我們日常開發的過程中難免會碰到一些選項的需求,下面是我針對我們該次需求做的一個小的Demo,閑話不多說了,上圖片,上代碼。

這樣在我們選擇上面一個Cell進行點擊的時候,我會通過一個代理把數據傳遞到下面的頁面,下面是代碼

//// LCAlertListView.h// MeiMeiDu//// Created by 韓偉佳 on 16/4/6.// Copyright © 2016年 LangCuang. All rights reserved.// #import <UIKit/UIKit.h>@class LCAlertListView; @protocol LCAlertListViewDelegate <NSObject> -(void)alertListView:(LCAlertListView*)view didSelectedRow:(NSInteger)row; @end @interface LCAlertListView : UIView<UITableViewDataSource, UITableViewDelegate> -(instancetype)initWithFrame:(CGRect)frame datas:(NSArray*)datas;-(instancetype)initWithFrame:(CGRect)frame datas:(NSArray*)datas count:(NSArray*)counts;@property(nonatomic, strong) id<LCAlertListViewDelegate> delegate;@end

下面是具體實現

//// LCAlertListView.m// MeiMeiDu//// Created by 韓偉佳 on 16/4/6.// Copyright © 2016年 LangCuang. All rights reserved.// #import "LCAlertListView.h"#import "NoFreeCell.h" static CGFloat TableViewHeight ; @implementation LCAlertListView{ UITableView* mTableView; NSArray* tableData; NSArray* visiableData; NSArray* visiableCount; UIButton* backgroundBtn;} -(instancetype)initWithFrame:(CGRect)frame datas:(NSArray*)datas{ if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; backgroundBtn = [[UIButton alloc] initWithFrame:frame]; backgroundBtn.backgroundColor = RGBA(88, 88, 88, 0.8); [backgroundBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:backgroundBtn]; tableData = datas; TableViewHeight = (datas.count + 1) * 44 + 20; mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, TableViewHeight) style:UITableViewStylePlain]; [mTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; mTableView.delegate = self; mTableView.dataSource = self; [self addSubview:mTableView]; [UIView animateWithDuration:.25 animations:^{ [mTableView setFrame:CGRectMake(0, kScreenHeight - TableViewHeight, kScreenWidth, TableViewHeight)]; } completion:^(BOOL finished) {  }]; } return self;}-(instancetype)initWithFrame:(CGRect)frame datas:(NSArray*)datas count:(NSArray*)counts{ if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; backgroundBtn = [[UIButton alloc] initWithFrame:frame]; backgroundBtn.backgroundColor = RGBA(88, 88, 88, 0.8); [backgroundBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:backgroundBtn]; visiableData = datas; visiableCount = counts; TableViewHeight = (datas.count + 1) * 44 + 20; mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, TableViewHeight) style:UITableViewStylePlain]; [mTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; mTableView.delegate = self; mTableView.dataSource = self; [self addSubview:mTableView]; [UIView animateWithDuration:.25 animations:^{ [mTableView setFrame:CGRectMake(0, kScreenHeight - TableViewHeight, kScreenWidth, TableViewHeight)]; } completion:^(BOOL finished) {  }]; } return self;}  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if(tableData.count > 0){ return [tableData count]; }else if (visiableCount.count > 0){ return [visiableCount count]; } return nil;} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell* cell; NoFreeCell *doubleCell; if([tableData count] <= 3 && [tableData count] > 0){ cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; cell.textLabel.text = tableData[indexPath.row]; return cell;  }else { static NSString *identifier = @"cell0"; doubleCell =[tableView dequeueReusableCellWithIdentifier:identifier]; if (doubleCell == nil){ doubleCell= [[NoFreeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; doubleCell.visibleRoleLabel.text = visiableData[indexPath.row]; doubleCell.showVisibleRoleLabel.text = visiableCount[indexPath.row]; } return doubleCell; } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger row = indexPath.row; [self dismiss:row];} -(void)dismiss:(NSInteger) row{ if (_delegate && [_delegate respondsToSelector:@selector(alertListView:didSelectedRow:)]) { [_delegate alertListView:self didSelectedRow:row]; }  [UIView animateWithDuration:.15 animations:^{ [mTableView setFrame:CGRectMake(0, kScreenHeight, kScreenWidth, TableViewHeight)]; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(void)dismiss{ [UIView animateWithDuration:.15 animations:^{ [mTableView setFrame:CGRectMake(0, kScreenHeight, kScreenWidth, TableViewHeight)]; } completion:^(BOOL finished) { [self removeFromSuperview]; }];}@end

上面的NoFree 文件只是一個自定義的Cell,我們可以根據自己的需求自己設計,就不上傳了,最后我們說說用法:

LCAlertListView* alertListView = [[LCAlertListView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) datas:visibleRoleArray count:visibleRoleCountArray]; alertListView.delegate = self; [[[self.view superview] superview] addSubview:alertListView];

下面是代理傳值的使用

#pragma mark - LCAlertListViewDelegate-(void)alertListView:(LCAlertListView *)view didSelectedRow:(NSInteger)row{ if(didSelectedIndex == 0){ testVisibleRole = visibleRoleArray[row]; }else{ testData = datas[row]; }  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:didSelectedIndex inSection:0]; [_myTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];}

這樣,我們的AlertTableVIew 就做好了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 茌平县| 夏津县| 青岛市| 伽师县| 莱阳市| 建宁县| 宾阳县| 洛宁县| 晋宁县| 将乐县| 澄城县| 大冶市| 海南省| 岑溪市| 鄂托克旗| 沾化县| 罗甸县| 兴和县| 鄂托克前旗| 芦山县| 渭源县| 深州市| 南通市| 临安市| 青州市| 肃南| 咸宁市| 拜泉县| 朝阳区| 五峰| 信宜市| 运城市| 镇平县| 拜城县| 彰武县| 崇仁县| 龙江县| 凤城市| 凤翔县| 镇康县| 德清县|