工作生活

普通弹出自定义View

2019-07-02  本文已影响0人  守护地中海的花

自定义View

@property(nonatomic,weak)BaseVC *parentVC;
#define kSelfHeight (287*ADAPTER_WIDTH)
@property(nonatomic,strong)UIControl *bgControl;


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self createProperty];
        [self createUI];
        [self startAnimation];
    }
    return self;
}
- (void)dealloc
{
    NSLog(@"WPPPickerCateView---dealloc");
}
- (void)createProperty
{
    self.backgroundColor = [UIColor whiteColor];
    [self.bgControl addSubview:self];
    self.frame = CGRectMake(0, HEIGHT, WIDTH, kSelfHeight);
}
- (void)createUI
{
    
}
- (void)setParentVC:(BaseVC *)parentVC
{
    _parentVC = parentVC;
    [parentVC.view addSubview:self.bgControl];
}
#pragma mark - 点击事件
- (void)clickBgControl:sender
{
    [self endAnimation];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.21 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeAllSubviews];
        [self.bgControl removeAllSubviews];
        [self.bgControl removeFromSuperview];
    });
}
#pragma mark - 动画
- (void)startAnimation
{
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, HEIGHT - kSelfHeight, WIDTH, kSelfHeight);
    }];
}
- (void)endAnimation
{
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, HEIGHT, WIDTH, kSelfHeight);
    }];
}
#pragma mark - Lazy懒加载区域
- (UIControl *)bgControl
{
    if (!_bgControl)
    {
        UIControl *bgControl = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        [sharedAppDelegate.window addSubview:bgControl];
        bgControl.backgroundColor = RGB(0, 0, 0, 0.2);
        [bgControl addTarget:self action:@selector(clickBgControl:) forControlEvents:UIControlEventTouchDown];
        _bgControl = bgControl;
    }
    return _bgControl;
}
上一篇下一篇

猜你喜欢

热点阅读