提供show方法
- 把self添加到Window上、设置尺寸
- 把其他view添加到self上
- 不用
- (void)layoutSubviews {
- 初始化创建时设置,或show里设置
- 开始动画,里面设置最终值
- 蒙版、显示view分开,各做各的(都在1个view中)
- iOS 自定义弹框
私有dismiss
- 完成后从super中移除
- 完成后,状态还原成初始——>下次再用
进阶self的背景就是蒙版cover
- 不要设置
self.alpha
值,把里面子控件也透明处理了
- 直接设置
self.backgroundColor =
,做蒙版效果!
- 不用
- (void)layoutSubviews {
#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
网友评论