项目需要引导图,简单介绍实现记录一下

问题:IOS自定义如何添加引导遮罩?

解决:思路为当前需要显示遮罩的View,添加一层半透明遮罩类似于蒙版(PS中常用),在需要引导的控件上,勾勒出镂空效果,并在上,下,左右不分根据自己需要,显示文字效果。

注意:如需添加图片效果,了解大体思路应该不难。


-(void)showGuidView{NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];if(![[defaults objectForKey:@"showGuidViewStatues"] isEqualToString:@"1"]){[self setGuidViewTextView:self.directionGradleView andContent:@"xxxxx,点击屏幕下一项" andTag:1001 andOffsetUp:YES];}
}-(void)setGuidViewTextView:(UIView*)attachView andContent:(NSString*)content andTag:(int)tag andOffsetUp:(BOOL) upOffset{
//创建需要显示遮罩空间路径UIBezierPath *tempPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(attachView.frame.origin.x, attachView.frame.origin.y, attachView.bounds.size.width, attachView.bounds.size.height) byRoundingCorners:(UIRectCornerTopLeft |UIRectCornerTopRight |UIRectCornerBottomRight|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(4, 4)];//获取手机屏幕大小并填充背景颜色,半透明UIView *guideView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];guideView.backgroundColor = [UIColor blackColor];guideView.alpha = 0.6;guideView.layer.mask = [self addTransparencyViewWith:tempPath];//用来区分每个引导标签,后续删除使用guideView.tag =tag;//控件文字显示UITextView *textView = nil;// 文字内容if(upOffset){if(tag == 1002){textView = [[UITextView alloc] initWithFrame:CGRectMake(attachView.frame.origin.x-attachView.bounds.size.width, attachView.frame.origin.y-50, guideView.bounds.size.width, attachView.bounds.size.height)];}else{textView = [[UITextView alloc] initWithFrame:CGRectMake(attachView.frame.origin.x, attachView.frame.origin.y-50, guideView.bounds.size.width, attachView.bounds.size.height)];}}else{textView = [[UITextView alloc] initWithFrame:CGRectMake(attachView.frame.origin.x, attachView.frame.origin.y+50, guideView.bounds.size.width/2, attachView.bounds.size.height*2)];}textView.backgroundColor = UIColor.clearColor;textView.selectable = NO;textView.font =[UIFont fontWithName:@"System" size:16];textView.font = [UIFont boldSystemFontOfSize:16];textView.textColor = UIColor.whiteColor;textView.text = content;[guideView addSubview:textView];//显示引导页面[[UIApplication sharedApplication].keyWindow addSubview:guideView];//为引导页面添加点击事件,方便更换下一个UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GuiViewEvent:)];//设置需要连续点击几次才响应,默认点击1次[tapGesture setNumberOfTapsRequired:1];[guideView addGestureRecognizer:tapGesture];
}/**引导页面点击事件*/
-(void)GuiViewEvent:(UITapGestureRecognizer *)gesture
{
//根据自定TAG 检查并删除上一个引导页面if([[UIApplication sharedApplication].keyWindow viewWithTag:1001] != nil){//处理事件[[[UIApplication sharedApplication].keyWindow viewWithTag:1001]removeFromSuperview];NSString* guidNextStr =@"xxxxxxx,点击屏幕下一项";[self setGuidViewTextView:self.throttleGradleView andContent:guidNextStr andTag:1002 andOffsetUp:YES];}else if([[UIApplication sharedApplication].keyWindow viewWithTag:1002] != nil){//处理事件[[[UIApplication sharedApplication].keyWindow viewWithTag:1002]removeFromSuperview];NSString* guidNextStr=@"xxxxxxx点击屏幕下一项";[self setGuidViewTextView:self.settingBtn andContent: guidNextStr andTag:1003 andOffsetUp:NO];}else if([[UIApplication sharedApplication].keyWindow viewWithTag:1003] != nil){//处理事件[[[UIApplication sharedApplication].keyWindow viewWithTag:1003]removeFromSuperview];NSString* guidNextStr=@"xxxxxxxxx,点击屏幕开始游戏";[self setGuidViewTextView:self.onHawkeyeBtn andContent: guidNextStr andTag:1004 andOffsetUp:NO];}else if([[UIApplication sharedApplication].keyWindow viewWithTag:1004] != nil){[[[UIApplication sharedApplication].keyWindow viewWithTag:1004]removeFromSuperview];NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];[defaults setValue:@"1" forKey:@"showGuidViewStatues"];[defaults synchronize];}}
//返回引导依附View区域
- (CAShapeLayer *)addTransparencyViewWith:(UIBezierPath *)tempPath{UIBezierPath *path = [UIBezierPath bezierPathWithRect:[UIScreen mainScreen].bounds];[path appendPath:tempPath];path.usesEvenOddFillRule = YES;CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.path = path.CGPath;
//    shapeLayer.fillColor= [UIColor blackColor].CGColor;  //其他颜色都可以,只要不是透明的
//    shapeLayer.fillColor =[UIColor clearColor].CGColor;shapeLayer.fillRule=kCAFillRuleEvenOdd;return shapeLayer;
}

IOS 开发引导遮罩相关推荐

  1. 【VMware中搭建iOS开发环境的引导工具】

    最近临时接手iOS开发,在VMware 9.0中搭建了Xcode + iPhone SDK开发环境,本来打算下笔一记,但这个环境的搭建教程网上一抓一大把,bill就不再赘述了.但是bill在引导工具的 ...

  2. iOS开发之应用首次启动显示用户引导 - 疯狂的萝卜 - 博客园

    iOS开发之应用首次启动显示用户引导 这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面  基本上都是使用UIScrollView 来实现, 新建一个 ...

  3. 【IOS开发进阶系列】动画专题

    1 CALayer IOS SDK详解之CALayer(一) http://doc.okbase.net/Hello_Hwc/archive/123447.html 1.1 基本概念 1.1.1 CA ...

  4. iOS开发常用第三方类库

    转:https://github.com/iOShuyang/Book-Recommend-Github Objective-C   Swift Objective-C 框架搭建   Swift 基础 ...

  5. 那些在学习iOS开发前就应该知道的事(part 1)

    2019独角兽企业重金招聘Python工程师标准>>> 英文原文:Things I wish I had known before starting iOS development- ...

  6. IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例

    IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...

  7. 1、ios开发之 内购

    大家都知道做iOS开发本身的收入有三种来源:出售应用.内购和广告.国内用户通常很少直接购买应用,因此对于开发者而言(特别是个人开发者),内购和广告收入就成了主要的收入来源.内购营销模式,通常软件本身是 ...

  8. iOS开发月报#10|201904

    这里记录过去一个月,我看到的值得分享的内容,包含但不限于iOS知识,每个月的最后一天发布. 欢迎推荐内容,可以前往zhangferry/iOSMonthlyReport提交issue. Tips 关于 ...

  9. iOS开发UIScrollView的底层实现

    起始 做开发也有一段时间了,经历了第一次完成项目的激动,也经历了天天调用系统的API的枯燥,于是就有了探索底层实现的想法. 关于scrollView的思考 在iOS开发中我们会大量用到scrollVi ...

最新文章

  1. “安卓之父”的新公司倒了:拿到腾讯投资,成为硅谷独角兽,五年只出了一款手机...
  2. 进程间通信(6) 邮槽
  3. ext时间控件Ext.ux.form.DateTimeField和Ext.form.DateField的用法比较
  4. MASK -RCNN
  5. Vue项目部署,打包发布上线
  6. 训练日志 2019.2.14
  7. dorehtml.php,帝国cms后台实现刷新多栏目内容页的方法详解
  8. word里面用mathtype编辑公式转成PDF后出现乱码
  9. Java Web实战篇:增强for循环实现原理和for循环实战性能优化
  10. 送给女朋友的情人节礼物---超贴心小程序
  11. 初等函数导数公式 ,积分表
  12. Python 识别图片文字( Tesseract 安装使用 )
  13. webservice接口对接
  14. 【应用回归分析】一元简单线性回归显著性检验,t检验和F检验统计量抽样分布推导
  15. java实现求调和数列的和,即:1/1 + 1/2 + ... + 1/n
  16. android 进程通信
  17. 2021-2025年中国冷链跟踪和监测系统行业市场供需与战略研究报告
  18. 高德足迹点Android,高德地图怎么点亮城市 足迹地图查看方法
  19. python如何使用多线程_python如何使用多线程
  20. Zabbix 监控功能实现(监控数据库,使用percona 优化数据库的监控,监控java应用,Agent端 主动传输数据,Zabbix proxy 的使用,Zabbix 监控 + 智能降噪告警)

热门文章

  1. 同时安装了天正8.0和AUTO CAD2007为什么双击天正每次打开的都是AUTO CAD2007?
  2. MySQL的数据备份
  3. tkinter-TinUI-xml实战(5)TinUIxml编辑器
  4. 当我们回顾过去,畅望未来,阻挡我们的道路是否很多,这都是N
  5. Oracle甲骨文11G版本快速安装
  6. 愚人节,聊聊那些开源的「傻问题」
  7. GBase 8s支持的驱动连接
  8. 第二届中国SaaS产业峰会-深圳站——挖掘SaaS的深度价值
  9. 零知识证明:安全定义
  10. 「MtOI2019」幽灵乐团