美文网首页工作生活
普通弹出自定义View

普通弹出自定义View

作者: 守护地中海的花 | 来源:发表于2019-07-02 09:37 被阅读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;
    }
    

    相关文章

      网友评论

        本文标题:普通弹出自定义View

        本文链接:https://www.haomeiwen.com/subject/kjbacctx.html