iOS 自定义底部弹出视图

因为最近用到  百度下吧  乱糟糟  索性自己写,果然自己写才是王道!!!!!!

.h文件

//
//  XJALertView.h
//
//  Created by 王小胜 on 2018/6/4.
//  Copyright © 2018年 王小胜. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface XJALertView : UIView
- (void)showAlert;
- (void)dismissAlert;
@end

.m文件

//
//  XJALertView.m
//
//  Created by 王小胜 on 2018/6/4.
//  Copyright © 2018年 王小胜. All rights reserved.
//

#import "XJALertView.h"

@interface XJALertView ()
@property (nonatomic, strong) UIView *btnBack;
@end

@implementation XJALertView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addElement];
    }
    return self;
}

- (void)addElement {
    self.backgroundColor = [UIColor blackColor];
    self.alpha = 0.2;
    
    _btnBack = [[UIView alloc]init];
    _btnBack.backgroundColor = [UIColor greenColor];
}

- (void)showAlert {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:self];
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissAlert)]];
    //遮罩
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0.5;
    }];
    [window addSubview:_btnBack];
    
    [_btnBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.bottom.equalTo(self);
        make.height.mas_equalTo(150);
    }];

    self.btnBack.transform = CGAffineTransformMakeTranslation(0.01, Screen_W);
    [UIView animateWithDuration:0.3 animations:^{
        self.btnBack.transform = CGAffineTransformMakeTranslation(0.01, 0.01);
    }];
}

- (void)dismissAlert {
    [UIView animateWithDuration:0.3 animations:^{
        self.btnBack.transform = CGAffineTransformMakeTranslation(0.01, Screen_W);
        self.btnBack.alpha = 0.2;
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        [self.btnBack removeFromSuperview];
    }];
}

@end


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值