1.遮罩制作
重载layoutSubviews函数,要了解这个函数就看看UIView生命周期
_bottomHeight :下面弹出框的高度
CGAffineTransformMakeTranslation 定义运动方向负_bottomHeight表示0.3秒内移动这个距离
弹出结束后,即completion 后执行后面的内容
//在这个类里重载
@interface myActionSheet : UIView
@end
- (void)layoutSubviews {
[super layoutSubviews];
if (_bottomHeight > 0) {
[UIView animateWithDuration:0.3 animations:^{
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
self.bottomView.transform = CGAffineTransformMakeTranslation(0, -_bottomHeight);
} completion:^(BOOL finished) {
//自己想显示的内容
}];
_bottomHeight = 0;
}
}
2.当遮罩住屏幕后,点一下立马消失
#pragma mark - Override Method
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self dismiss];
}
- (void)dismiss {
[UIView animateWithDuration:0.3 animations:^{
self.backgroundColor = [UIColor clearColor];
self.bottomView.transform = CGAffineTransformMakeTranslation(0,CGRectGetHeight(self.bottomView.frame));
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
另外一种制造延迟的方法
self.collectionView.transform = CGAffineTransformMakeTranslation(0.01, self.HeightFrame);
[myGCDQueue executeInMainQueue:^{
[UIView animateWithDuration:0.3 animations:^{
self.collectionView.transform = CGAffineTransformMakeTranslation(0, 0);
self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
}completion:^(BOOL finished) {
}];
}afterDelaySecs:0.1];
@interface myGCDQueue : NSObject
//主线程延时执行gcd
+ (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec;
@end
@implementation myGCDQueue
+ (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec {
NSParameterAssert(block);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * sec),dispatch_get_main_queue(), block);
}
@end