iOS 蒙版弹窗

2018-07-27  本文已影响207人  geekAppke

提供show方法

私有dismiss

进阶self的背景就是蒙版cover

#define kPhoneNumButtonH 48
@interface BNCallPhoneView ()
@property (nonatomic, strong) UIButton *phoneNumButton;
@end

@implementation BNCallPhoneView
#pragma mark - Initial Methods
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = UIColorFromHexAndAlpha(0x000, 0.4);
    }
    return self;
}

#pragma mark - Actions
- (void)callPhoneButtonDidClick {
    [LOAppURLHandler callTel:self.phoneNum];
    [self hide];
}

#pragma mark - Public
- (void)show {
    self.frame = APP_KEYWINDOW.frame;
    [APP_KEYWINDOW addSubview:self];
    [self addSubview:self.phoneNumButton];

    [UIView animateWithDuration:0.3
        animations:^{
            self.phoneNumButton.bottom = kScreenHeight;
        }
        completion:^(BOOL finished){
        }];
}

- (void)hide {
    [UIView animateWithDuration:0.3
        animations:^{
            self.phoneNumButton.top = kScreenHeight;
        }
        completion:^(BOOL finished) {

            [UIView animateWithDuration:.25f
                animations:^{
                    self.alpha = 0.0f;
                }
                completion:^(BOOL finished) {
                    self.alpha = 1.0f; // 重复利用
                    [self removeFromSuperview];
                }];
        }];
}

#pragma mark - Private
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self hide];
}

#pragma mark - Lazy Loads
- (UIButton *)phoneNumButton {
    if (!_phoneNumButton) {
        _phoneNumButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_phoneNumButton setBackgroundImage:[UIImage imageWithColor:kColorWhite] forState:UIControlStateNormal];
        [_phoneNumButton setTitle:self.phoneNum forState:UIControlStateNormal];
        _phoneNumButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_phoneNumButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        _phoneNumButton.frame = CGRectMake(0, kScreenHeight, kScreenWidth, kPhoneNumButtonH);
        [_phoneNumButton addTarget:self action:@selector(callPhoneButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
        _phoneNumButton.adjustsImageWhenHighlighted = NO;
    }
    return _phoneNumButton;
}
@end
上一篇下一篇

猜你喜欢

热点阅读