iOS开发添加新手引导效果

时间:2022-02-08 08:57:28

往往项目中经常出现此类需求

iOS开发添加新手引导效果

用户通过点击引导按钮可响应页面附带按钮的点击事件。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//
// gzhguideview.h
// guideview
//
// created by 郭志贺 on 2020/5/29.
// copyright © 2020 郭志贺. all rights reserved.
//
 
#import <uikit/uikit.h>
 
ns_assume_nonnull_begin
 
@interface gzhguideview : uiview
 
 
-(void)showguide:(uiview*)view;//显示引导
-(void)dismissguide;//移除
 
@end
 
ns_assume_nonnull_end
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// gzhguideview.m
// guideview
//
// created by 郭志贺 on 2020/5/29.
// copyright © 2020 郭志贺. all rights reserved.
//
 
#import "gzhguideview.h"
 
@implementation gzhguideview
-(instancetype)initwithframe:(cgrect)frame{
 
  if (self = [super initwithframe:frame]) {
 
    self.backgroundcolor = [uicolor colorwithred:0 green:0 blue:0 alpha:0.6];
    //主要代码 添加路径
    uibezierpath *path = [uibezierpath bezierpathwithrect:frame];
    // 这里添加第二个路径 需要扣除的部分
    [path appendpath:[[uibezierpath bezierpathwithroundedrect:cgrectmake(100, 100, 150, 40) cornerradius:5] bezierpathbyreversingpath]];
 
    //渲染
    cashapelayer *shapelayer = [cashapelayer layer];
    shapelayer.path = path.cgpath;
    [self.layer setmask:shapelayer];
 
    //根据需求添加按钮 实现点击事件
    uibutton * button = [uibutton buttonwithtype:uibuttontypecustom];
    button.frame = cgrectmake(100, 100, 150, 40);
    [button addtarget:self action:@selector(buttonclick) forcontrolevents:uicontroleventtouchupinside];
    button.layer.cornerradius = 5.0f;
    button.layer.maskstobounds = yes;
    [self addsubview:button];
  }
 
  return self;
}
 
-(void)showguide:(uiview *)view{//添加
 
 
  [view.window addsubview:self];
  [view.window bringsubviewtofront:self];
  self.alpha = 1;
 
 
}
-(void)dismissguide{//移除
 
  [self removefromsuperview];
 
}
-(void)buttonclick{
  [self dismissguide];
  nslog(@"引导状态可点击");
 
}
@end

相应页面直接添加

?
1
2
3
4
5
6
7
gzhguideview * guide = [[gzhguideview alloc]initwithframe:cgrectmake(0, 0, kscreenwidth, kscreenheight)];
 
dispatch_async(dispatch_get_main_queue(), ^{
 
[guide showguide: self .view];
 
});

可根据不同需求进行不同的布局,核心代码就是添加路径

总结

到此这篇关于ios开发添加新手引导的实例代码的文章就介绍到这了,更多相关ios新手引导内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:http://www.cnblogs.com/guozhihe/p/12987221.html