IOS implements pop-up tabs with masks

Time:2021-7-26

In the process of our daily development, we will inevitably encounter the needs of some options. The following is a small demo I made for our needs. I won’t talk more. Let’s go to the pictures and code.

In this way, when we select the cell above to click, I will transfer the data to the following page through an agent. Here is the code

//
// LCAlertListView.h
// MeiMeiDu
//
//Created by Han Weijia 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

The following is the specific implementation

//
// LCAlertListView.m
// MeiMeiDu
//
//Created by Han Weijia 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

The above nofree file is just a custom cell. We can design it according to our own needs, so we don’t upload it. Finally, let’s talk about the usage:


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

The following is the use of proxy value transfer


#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];
}

In this way, our alerttableview is ready.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

VBS obtains the operating system and its version number

VBS obtains the operating system and its version number ? 1 2 3 4 5 6 7 8 9 10 11 12 ‘************************************** ‘*by r05e ‘* operating system and its version number ‘************************************** strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _  (“Select * from […]