当前位置: 代码迷 >> 综合 >> IOS 屏幕遮罩 Mask
  详细解决方案

IOS 屏幕遮罩 Mask

热度:72   发布时间:2023-12-15 01:58:43.0

效果图如下:

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

    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: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


  相关解决方案