這篇文章主要講解了iOS開發(fā)添加新手引導(dǎo)的代碼詳解,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)西雙版納免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
往往項(xiàng)目中經(jīng)常出現(xiàn)此類需求
用戶通過點(diǎn)擊引導(dǎo)按鈕可響應(yīng)頁面附帶按鈕的點(diǎn)擊事件。
// // 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
#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]; // 這里添加第二個(gè)路徑 需要扣除的部分 [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ù)需求添加按鈕 實(shí)現(xiàn)點(diǎ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)可點(diǎn)擊"); } @end
相應(yīng)頁面直接添加
gzhGuideView * guide = [[gzhGuideView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)]; dispatch_async(dispatch_get_main_queue(), ^{ [guide showGuide: self .view]; });
可根據(jù)不同需求進(jìn)行不同的布局,核心代碼就是添加路徑
看完上述內(nèi)容,是不是對(duì)iOS開發(fā)添加新手引導(dǎo)的代碼詳解有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文題目:iOS開發(fā)添加新手引導(dǎo)的代碼詳解
文章位置:http://www.rwnh.cn/article36/jisepg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、小程序開發(fā)、響應(yīng)式網(wǎng)站、定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)