iOS学习—制作全局遮罩

news/2024/7/20 21:56:53 标签: ios, 学习, cocoa, xcode, objective-c

 在.h文件中线声明show()方法

- (void)show;

.m文件中添加全屏遮罩,在遮罩上添加了一个选择框并添加了底部弹出的动画,可自行在其中添加tableview、pickerview等其他视图,并添加了点击选择框视图外区域隐藏

#import "MaskView.h"

@interface MaskView()

@property (nonatomic ,strong) UIView *deliverView; //底部View
@property (nonatomic ,strong) UIView *BGView; //遮罩

@end

@implementation MaskView

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        
    }
    return self;
}

- (void)appearClick {
 // ------全屏遮罩
    self.BGView = [[UIView alloc] init];
    self.BGView.frame = [[UIScreen mainScreen] bounds];
    self.BGView.tag = 100;
    self.BGView.backgroundColor = [HexColor(@"#000000") 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 = [HexColor(@"#000000") colorWithAlphaComponent:0.24];
    }];
    
    // ------底部弹出的View
    self.deliverView = [[UIView alloc] init];
//    self.deliverView.frame = CGRectMake(0, SCREEN_WIDTH, SCREEN_WIDTH, 306);
    ViewRadius(self.deliverView, 16);
    self.deliverView.backgroundColor = myCellColor;
    [appWindow addSubview:self.deliverView];
    [self.deliverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kWidth);
        make.height.mas_equalTo(306);
    }];
    // ------View出现动画
    self.deliverView.transform = CGAffineTransformMakeTranslation(0.01, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.5 animations:^{
        self.deliverView.transform = CGAffineTransformMakeTranslation(0.01, 0.01);
    }];
    
    [self.deliverView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(18);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(kWidth);
        make.height.mas_equalTo(48 * 5);
    }];
    
}
/**
 * 功能: View退出
 */
- (void)exitClick {
    NSLog(@"====");
    [UIView animateWithDuration:0.5 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];
    }];
}

@end


http://www.niftyadmin.cn/n/4933757.html

相关文章

配置:Terminal和oh-my-posh

目录 命令行安装oh-my-posh查看安装情况配置PowerShell启用oh-my-posh、设置主题配色安装字体Terminal中的配置 命令行安装oh-my-posh Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString(https://ohmy…

分布式定时任务系列5:XXL-job中blockingQueue的应用

传送门 分布式定时任务系列1:XXL-job安装 分布式定时任务系列2:XXL-job使用 分布式定时任务系列3:任务执行引擎设计 分布式定时任务系列4:任务执行引擎设计续 Java并发编程实战1:java中的阻塞队列 引子 这篇文章的…

使用阿里云服务器搭建Discuz论坛网站教程基于CentOS系统

阿里云百科分享使用阿里云服务器建站教程,本文是搭建Discuz论坛,Discuz!是一款通用的社区论坛软件系统,它采用PHP和MySQL组合的基础架构,为您提供高效的论坛解决方案。本文介绍如何在CentOS 7操作系统的ECS实例上搭建Discuz! X3.4…

山东布谷科技直播软件开发WebRTC技术:建立实时通信优质平台

在数字化的时代,实时通信成为了人们远程交流的主要方式,目前市场上也出现了很多带有实时通信交流的软件,实时通信符合人们现在的需求,所以在直播软件开发过程中,开发者也运用了实时通信技术为直播软件加入了实时通信的…

如何在CSS中水平居中一个元素?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 使用 margin: 0 auto⭐ 使用 Flexbox 布局⭐ 使用绝对定位和负边距⭐ 使用表格布局⭐ 使用网格布局⭐ 写在最后 ⭐ 专栏简介 前端入门之旅:探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅…

每日一题——寻找旋转排序数组中的最小值(I)

寻找旋转排序数组中的最小值——I 题目链接 思路 首先我们以数组[1,2,3,4,5,6,7]举个例子,经过旋转后它无非就这两种情况: 情况一:旋转过后数组变成两段有序数列: 情况二:旋转过后数组不变,仍然有序&…

24届近3年南京信息工程大学自动化考研院校分析

今天给大家带来的是南京信息工程大学控制考研分析 满满干货~还不快快点赞收藏 一、南京信息工程大学 学校简介 南京信息工程大学位于南京江北新区,是一所以大气科学为特色的全国重点大学,由江苏省人民政府、中华人民共和国教育部、中国气…

jdk自带的com.sun.tools库的常见用法

jdk自带的com.sun.tools库的常见用法 本文主要介绍利用jdk自带的tools.jar库生成常见java语法。使用场景主要是编译时注解,如lombok等,大致原理为在编译的时候插入相应的语句,体现在class文件上会多出相应语句。 以下内容主要是提炼了一下相…