IOS 屏幕遮罩 Mask

来源:互联网 发布:手机监听监控定位软件 编辑:程序博客网 时间:2024/05/16 07:20

效果图如下:

 //alpha 0.0  白色   alpha 1:黑色   alpha 01:遮罩颜色,逐渐

    self.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.4];



代码如下:

#import "TFMaskView.h"@interface TFMaskView(){    UIView      *_backGroundView;}@end@implementation TFMaskView- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];        if (self)    {        [self loadMaskView];        [self initBtnView];    }        return self;}- (void)loadMaskView{    self.frame = CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT);    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];    self.userInteractionEnabled = YES;    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissHintView)]];        _backGroundView = [[UIView alloc] init];    _backGroundView.backgroundColor = [UIColor clearColor];    _backGroundView.frame = CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT);    [self addSubview:_backGroundView];        //self.alpha = 0.0;}- (void)initBtnView{        UIView *_mainView = [[UIView alloc]initWithFrame:CGRectMake(15, 64, kDEVICEWIDTH - 30, 200)];    _mainView.backgroundColor = [UIColor whiteColor];    [_backGroundView addSubview:_mainView];        UIButton *_checkOrderDetailBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 60, kDEVICEWIDTH - 30, 48)];    _checkOrderDetailBtn.backgroundColor = [CHUtil colorWithHexString:@"eaeaea"];    [_checkOrderDetailBtn addTarget:self action:@selector(checkOrderDetailBtnClick) forControlEvents:UIControlEventTouchUpInside];    [_checkOrderDetailBtn setTitle:@"查看详情" forState:UIControlStateNormal];    _checkOrderDetailBtn.titleLabel.textColor = [UIColor whiteColor];    _checkOrderDetailBtn.layer.cornerRadius = 4;    [_mainView addSubview:_checkOrderDetailBtn];        UIButton *_startOrderBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 130, kDEVICEWIDTH - 30, 48)];    _startOrderBtn.backgroundColor = [CHUtil colorWithHexString:@"0b8ef0"];;    [_startOrderBtn addTarget:self action:@selector(startOrderBtnClick) forControlEvents:UIControlEventTouchUpInside];    [_startOrderBtn setTitle:@"立即支付" forState:UIControlStateNormal];    _startOrderBtn.titleLabel.textColor = [UIColor whiteColor];    _startOrderBtn.layer.cornerRadius = 4;    [_mainView addSubview:_startOrderBtn];}#pragma mark -- clicked method- (void)checkOrderDetailBtnClick{    CHDebugLog(@"---checkOrderDetailBtnClick----");}- (void)startOrderBtnClick{    CHDebugLog(@"----startOrderBtnClick---");}#pragma mark -- show or dismiss View- (void)showHintView{    [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:self];        self.alpha = 0.0;    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{                self.alpha = 1.0;            } completion:^(BOOL finished)     {              }];}- (void)dismissHintView{    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{                self.alpha = 0.0;            } completion:^(BOOL finished){                [self removeFromSuperview];    }];}@end


0 0
原创粉丝点击