类似于系统UIActionSheet弹出时Sheet上升加蒙版点击还原

项目中又做到下图的个人页界面,又要重新开始解决各个控件重叠触发的问题,决定加蒙版,然后又发现导航栏没被遮住,就决定加载Window上,没什么难得东西,只是为了以后直接拿来用罢了

WechatIMG20.jpeg

直接上代码,加上注释应该很清楚了

@property (nonatomic,strong) AppDelegate *appdelegate;
@property (nonatomic,strong) UIView      *backgroundView; // 蒙版
// 懒加载
- (UIView *)backgroundView {
    
    if (!_backgroundView) {
        
        _backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _backgroundView.backgroundColor = [UIColor clearColor];
    }
    return _backgroundView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
}
- (void)buttonClick:(UIButton*)button {
   // 添加手势到window 点击还原
  UITapGestureRecognizer *tapLeftDouble  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(magnifyImage:)];
    [_appdelegate.window addGestureRecognizer:tapLeftDouble];

 [_appdelegate.window addSubview:self.backgroundView]; // 放置蒙版
 // 改变蒙版颜色及透明度
 [UIView animateWithDuration:.15f animations:^{
        self.backgroundView.backgroundColor = RGB(0, 0, 0);
        self.backgroundView.alpha = .4f;
    }];
// 动画改变目标view上升速度
 CATransition *animation = [CATransition animation];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [animation setDuration:.15f];
    [animation setType:kCATransitionMoveIn];
    [animation setSubtype: kCATransitionFromTop];
    
// _dateView 是我使用的view  此处替换成自己的
    _dateView       = [SHDatePickerView viewFromXIB];
    _dateView.frame = CGRectMake(0, viewHeight - 261, viewWidth, 261);
    [_appdelegate.window addSubview:_dateView];
    
    [_dateView.layer addAnimation:animation forKey:@"Reveal"];

}
// 手势还原
-(void)magnifyImage:(UIGestureRecognizer *)gesture
{
        [_dateView removeFromSuperview];
        [self.backgroundView removeFromSuperview];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,446评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,250评论 4 61
  • 我转着笔,草稿上算了几个公式。 戴着白色耳机,偶尔哼出几句。 稍一侧目,你安静地睡在地图本上。 那个六月真好。 <...
    林下默宛阅读 363评论 5 9
  • 最近因为项目原因,买了阿里云九块九来用。部署项目的时候一下子就遇到了问题,mysql无法启动。当时是刚刚yum i...
    BIDIU猿阅读 10,409评论 1 1
  • 突然想把记忆里的每一个人都写进故事里,第一个想到的便是高中两年的班主任——强哥(当然这是其他同学对你的称...
    疏狸阅读 459评论 0 0