这篇文章主要介绍了iOS开发添加新手引导效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
往往项目中经常出现此类需求

用户通过点击引导按钮可响应页面附带按钮的点击事件。
//
// 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
//
// 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
相应页面直接添加
gzhGuideView * guide = [[gzhGuideView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
dispatch_async(dispatch_get_main_queue(), ^{
[guide showGuide: self .view];
});
可根据不同需求进行不同的布局,核心代码就是添加路径
总结
到此这篇关于iOS开发添加新手引导的实例代码的文章就介绍到这了,更多相关ios新手引导内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
织梦狗教程
本文标题为:iOS开发添加新手引导效果
基础教程推荐
猜你喜欢
- Android中的webview监听每次URL变化实例 2023-01-23
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Flutter手势密码的实现示例(附demo) 2023-04-11
- Android多返回栈技术 2023-04-15
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- android studio按钮监听的5种方法实例详解 2023-01-12
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
