提供show方法
- 把self添加到Window上、設(shè)置尺寸
- 把其他view添加到self上
- 不用
- (void)layoutSubviews {
- 初始化創(chuàng)建時設(shè)置嚼酝,或show里設(shè)置
- 開始動畫,里面設(shè)置最終值
- 蒙版竟坛、顯示view分開闽巩,各做各的(都在1個view中)
- iOS 自定義彈框
私有dismiss
- 完成后從super中移除
- 完成后钧舌,狀態(tài)還原成初始——>下次再用
進階self的背景就是蒙版cover
- 不要設(shè)置
self.alpha
值,把里面子控件也透明處理了
- 直接設(shè)置
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; // 重復(fù)利用
[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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者