//
// TestAlertView.m
// YanKa
//
// Created by Lei on 2021/9/6.
//
#import "TestAlertView.h"
@interface TestAlertView ()
@property (nonatomic, strong) UIView *bgView; //半透明黑色背景
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation TestAlertView
-(instancetype)initWithFrame:(CGRect)frame{
self=[superinitWithFrame:frame];
if(self) {
[selfaddSubview:self.bgView];
}
return self;
}
#pragma mark- 懒加载
-(UIView*)bgView{
if(!_bgView) {
_bgView = [[UIView alloc] initWithFrame:self.frame];
[_bgView setBackgroundColor:[UIColor clearColor]];
[_bgViewsetAlpha:0];
[_bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideMyPicker)]];
}
return _bgView;
}
-(UIView *)containerView{
if (!_containerView) {
_containerView = [[UIView alloc] initWithFrame:CGRectMake(0, _bgView.height - 300, self.width, 300)];
_containerView.backgroundColor=[UIColor orangeColor];
[_containerView addSubview:self.tableView];
[_containerView setTransform:CGAffineTransformMakeTranslation(0, CGRectGetHeight(_containerView.frame))];
}
return _containerView;
}
-(UITableView *)tableView{
if(!_tableView) {
_tableView=[[UITableView alloc] initWithFrame:CGRectMake(14, 0, SCREEN_WIDTH-28, 250) style:UITableViewStylePlain];
_tableView.layer.cornerRadius=10;
_tableView.layer.masksToBounds=YES;
_tableView.backgroundColor=[UIColor blueColor];
_tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
_tableView.scrollEnabled=NO;
//解决视图漂移或者闪动解决方法
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
_tableView.sectionHeaderHeight=0;
_tableView.sectionFooterHeight=0;
// _tableView.dataSource=self;
// _tableView.delegate=self;
// [_tableView registerClass:[PopPhotoAuthCell class] forCellReuseIdentifier:@"PopPhotoAuthCell"];
}
return _tableView;
}
#pragma mark - 点击透明背景hidden
- (void)hideMyPicker{
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[_bgViewsetAlpha:1];
[_containerView setTransform:CGAffineTransformIdentity];
}completion:^(BOOLcompleted) {
[selfsetPickerHidden:YES];
}];
}
-(void)showAlertView{
[self addSubview:self.containerView];
[self setPickerHidden:NO];
}
#pragma mark - Show/hide PickerView methods
-(void)setPickerHidden:(BOOL)hidden{
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
if(hidden) {
[_bgViewsetAlpha:0];
[_containerView setTransform:CGAffineTransformMakeTranslation(0, CGRectGetHeight(_containerView.frame))];
}else{
[_bgViewsetAlpha:1.0];
[_containerView setTransform:CGAffineTransformIdentity];
}
}completion:^(BOOLcompleted) {
if(completed && hidden){
[selfremoveFromSuperview];
}
}];
}
@end
网友评论