iOS開發(fā)添加新手引導(dǎo)效果
更新時間:2020年05月29日 15:34:10 作者:MrGuo還在搬磚
這篇文章主要介紹了iOS開發(fā)添加新手引導(dǎo)效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
往往項目中經(jīng)常出現(xiàn)此類需求
用戶通過點擊引導(dǎo)按鈕可響應(yīng)頁面附帶按鈕的點擊事件。
// // 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;//顯示引導(dǎo) -(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]; //根據(jù)需求添加按鈕 實現(xiàn)點擊事件 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(@"引導(dǎo)狀態(tài)可點擊"); } @end
相應(yīng)頁面直接添加
gzhGuideView * guide = [[gzhGuideView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)]; dispatch_async(dispatch_get_main_queue(), ^{ [guide showGuide: self .view]; });
可根據(jù)不同需求進行不同的布局,核心代碼就是添加路徑
總結(jié)
到此這篇關(guān)于iOS開發(fā)添加新手引導(dǎo)的實例代碼的文章就介紹到這了,更多相關(guān)ios新手引導(dǎo)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
iOS使用pageViewController實現(xiàn)多視圖滑動切換
這篇文章主要為大家詳細介紹了iOS使用pageViewController實現(xiàn)多視圖滑動切換,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-06-06Objective-C方法的聲明實現(xiàn)及調(diào)用方法
這篇文章主要介紹了Objective-C方法的聲明實現(xiàn)及調(diào)用方法,包括五參數(shù)的方法和單個參數(shù)的方法,結(jié)合實例代碼給大家介紹的非常詳細,感興趣的朋友一起看看吧2024-02-02iOS開發(fā)之?dāng)r截URL轉(zhuǎn)換成本地路由模塊URLRewrite詳解
這篇文章主要給大家介紹了關(guān)于iOS開發(fā)之?dāng)r截URL轉(zhuǎn)換成本地路由模塊URLRewrite的相關(guān)資料,這是最近在工作中遇到的一個需求,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編來一起看看吧。2017-08-08