这种遮罩一般做为新手引导页面。一般有镂空的一部分,附有描述,指引用户第一次进入界面该如何操做,只显示一次。app
优势:程序实现简单,便捷。 缺点:适配不一样机型须要多套图片(Android心里是崩溃的),后期迭代界面改动则要更新图片,UI工做量庞大。
优势:UI只提供描述的图片便可,减小应用大小,灵活适配不一样机型。 缺点:代码较第一种略多,后期迭代界面改动要更新控件frame。
核心代码:iview
- (void)creatControlWithType:(HKGuidePageType)type completion:(FinishBlock)completion { _finish = completion; // 遮盖视图 CGRect frame = [UIScreen mainScreen].bounds; UIView *bgView = [[UIView alloc] initWithFrame:frame]; bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7f]; [bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]]; [[UIApplication sharedApplication].keyWindow addSubview:bgView]; // 信息提示视图 UIImageView *imgView = [[UIImageView alloc] init]; [bgView addSubview:imgView]; // 第一个路径 UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame]; switch (type) { case HKGuidePageTypeHome: // 下一个路径,圆形 [path appendPath:[UIBezierPath bezierPathWithArcCenter:KSuitPoint(227, 188) radius:KSuitFloat(46) startAngle:0 endAngle:2 * M_PI clockwise:NO]]; imgView.frame = KSuitRect(220, 40, 100, 100); imgView.image = [UIImage imageNamed:@"hi"]; _guidePageKey = HKGuidePageHomeKey; break; case HKGuidePageTypeMajor: // 下一个路径,矩形 [path appendPath:[[UIBezierPath bezierPathWithRoundedRect:KSuitRect(5, 436, 90, 40) cornerRadius:5] bezierPathByReversingPath]]; imgView.frame = KSuitRect(100, 320, 120, 120); imgView.image = [UIImage imageNamed:@"ly"]; _guidePageKey = HKGuidePageMajorKey; break; default: break; } // 绘制透明区域 CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = path.CGPath; [bgView.layer setMask:shapeLayer]; }