常見(jiàn)的淡入淡出動(dòng)畫(huà)。
1.創(chuàng)建baseView(子視圖),位置設(shè)置為屏幕下邊
- (UIView *)baseView {
if (!_baseView) {
_baseView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100)];
_baseView.backgroundColor = COLOR_B8;
}
return _baseView;
}
2.布局完成后,調(diào)用show方法
1)self背景色從clear 到某個(gè)指定顏色
2)baseView.frame到需要顯示的位置
- (void)show {
_baseViewHeight = 49 * (_items.count + 1) + 5;
self.backgroundColor = [UIColor clearColor];
[[UIApplication sharedApplication].keyWindow addSubview:self];
[UIView animateWithDuration:0.35 animations:^{
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
self.baseView.frame = CGRectMake(0, SCREEN_HEIGHT-_baseViewHeight, SCREEN_WIDTH, _baseViewHeight);
} completion:^(BOOL finished) {
}];
}
3.點(diǎn)擊按鈕或者觸摸屏幕消失
- (void)clickItemBtnAction:(UIButton *)sender {
NSInteger index = sender.tag - 200;
[[UIApplication sharedApplication].keyWindow addSubview:self];
[UIView animateWithDuration:0.35 animations:^{
self.backgroundColor = [UIColor clearColor];
self.baseView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, _baseViewHeight);
} completion:^(BOOL finished) {
if (_delegate && [_delegate respondsToSelector:@selector(bottomView:selected:)]) {
[_delegate bottomView:self selected:index];
}
}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self];
point = [self.baseView.layer convertPoint:point fromLayer:self.layer];
if (![self.baseView.layer containsPoint:point]) {
[self clickItemBtnAction:self.btnCancel];
}
}