123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // YLBaseAlertView.m
- // mask
- //
- // Created by 翟玉磊 on 2018/12/27.
- // Copyright © 2018 翟玉磊. All rights reserved.
- //
- #import "YLBaseAlertView.h"
- @interface YLBaseAlertView ()
- @property (strong, nonatomic) UIView *backgroundView;
- @end
- @implementation YLBaseAlertView
- - (instancetype)init {
- if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
- self.backgroundColor = [UIColor clearColor];
-
- _clickBackgroundHide = YES;
- _backgroundView = [[UIView alloc] initWithFrame:self.frame];
- _backgroundView.backgroundColor = Color_Black;
- [self addSubview:_backgroundView];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor clearColor];
-
- _clickBackgroundHide = YES;
- _backgroundView = [[UIView alloc] initWithFrame:self.frame];
- _backgroundView.backgroundColor = Color_Black;
- [self addSubview:_backgroundView];
- }
- return self;
- }
- - (void)show {
- [[UIApplication sharedApplication].delegate.window addSubview:self];
- [self showBackground];
- [self showAlertAnimation];
- }
- - (void)dismiss {
- _contentView.hidden = YES;
- [self hideAlertAnimation];
- [self removeFromSuperview];
- }
- - (void)setContentView:(UIView *)contentView {
- _contentView = contentView;
- _contentView.center = self.center;
- [self addSubview:_contentView];
- }
- - (void)showBackground
- {
- _backgroundView.alpha = 0;
- [UIView beginAnimations:@"fadeIn" context:nil];
- [UIView setAnimationDuration:0.35];
- _backgroundView.alpha = 0.4;
- [UIView commitAnimations];
- }
- -(void)showAlertAnimation
- {
- CAKeyframeAnimation * animation;
- animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
- animation.duration = 0.30;
- animation.removedOnCompletion = YES;
- animation.fillMode = kCAFillModeForwards;
- NSMutableArray *values = [NSMutableArray array];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
- animation.values = values;
- [_contentView.layer addAnimation:animation forKey:nil];
- }
- - (void)hideAlertAnimation {
- [UIView beginAnimations:@"fadeIn" context:nil];
- [UIView setAnimationDuration:0.35];
- _backgroundView.alpha = 0.0;
- [UIView commitAnimations];
- }
- //点击屏幕空白处去掉键盘
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- if ([touches anyObject].view != _contentView && self.clickBackgroundHide) {
- // 判断点击的区域如果不是菜单按钮_btnMenu, 则关闭菜单
- [self dismiss];
- }
- }
- @end
|