#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
@property (nonatomic ,strong) UIView *deliverView; //底部View
@property (nonatomic ,strong) UIView *BGView; //遮罩
- (void)appearClick {
// ------全屏遮罩
self.BGView = [[UIView alloc] init];
self.BGView.frame = [[UIScreen mainScreen] bounds];
self.BGView.tag = 100;
self.BGView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
self.BGView.opaque = NO;
//--UIWindow的优先级最高,Window包含了所有视图,在这之上添加视图,可以保证添加在最上面
UIWindow *appWindow = [[UIApplication sharedApplication] keyWindow];
[appWindow addSubview:self.BGView];
// ------给全屏遮罩添加的点击事件
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(exitClick)];
gesture.numberOfTapsRequired = 1;
gesture.cancelsTouchesInView = NO;
[self.BGView addGestureRecognizer:gesture];
[UIView animateWithDuration:0.3 animations:^{
self.BGView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
}];
// ------底部弹出的View
self.deliverView = [[UIView alloc] init];
self.deliverView.frame = CGRectMake(0, SCREEN_WIDTH, SCREEN_WIDTH, SCREEN_WIDTH);
self.deliverView.backgroundColor = [UIColor whiteColor];
[appWindow addSubview:self.deliverView];
// ------View出现动画
self.deliverView.transform = CGAffineTransformMakeTranslation(0.01, SCREEN_HEIGHT);
[UIView animateWithDuration:0.3 animations:^{
self.deliverView.transform = CGAffineTransformMakeTranslation(0.01, 0.01);
}];
}
/**
* 功能: View退出
*/
- (void)exitClick {
NSLog(@"====");
[UIView animateWithDuration:0.3 animations:^{
self.deliverView.transform = CGAffineTransformMakeTranslation(0.01, SCREEN_HEIGHT);
self.deliverView.alpha = 0.2;
self.BGView.alpha = 0;
} completion:^(BOOL finished) {
[self.BGView removeFromSuperview];
[self.deliverView removeFromSuperview];
}];
}
MY_OC_ iOS_底部弹出View
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 该组件支持IOS11,适配iPhoneX的安全区域(safe area),项目已提交至Github可下载运行查看效...
- 封装底部弹出view库,调用非常简单。 先来看下效果 gif不是很清晰 ,效果还是很酷的。运行和真机效果都不错,那...
- 从底部弹出PopuWindow在开发中是一个经常用到的问题,代码枯燥,又没有什么技术含量,我就把它封装了一下,以最...