├── 123.gif
├── README.md
├── NewHandGuideDemo
├── NewHandGuideDemo
│ ├── guide_arrow@3x.png
│ ├── Info.plist
│ ├── Base.lproj
│ │ ├── Main.storyboard
│ │ └── LaunchScreen.storyboard
│ ├── Assets.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── AppDelegate.swift
│ ├── ViewController.swift
│ └── MYHGuideMaskView.swift
└── NewHandGuideDemo.xcodeproj
│ ├── project.xcworkspace
│ └── contents.xcworkspacedata
│ └── project.pbxproj
└── .gitignore
/123.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minyahui/NoviceGuide/HEAD/123.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NoviceGuide
2 | 新手引导
3 |
4 | 
5 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/guide_arrow@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/minyahui/NoviceGuide/HEAD/NewHandGuideDemo/NewHandGuideDemo/guide_arrow@3x.png
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | ## Playgrounds
32 | timeline.xctimeline
33 | playground.xcworkspace
34 |
35 | # Swift Package Manager
36 | #
37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38 | # Packages/
39 | # Package.pins
40 | # Package.resolved
41 | .build/
42 |
43 | # CocoaPods
44 | #
45 | # We recommend against adding the Pods directory to your .gitignore. However
46 | # you should judge for yourself, the pros and cons are mentioned at:
47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
48 | #
49 | # Pods/
50 |
51 | # Carthage
52 | #
53 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
54 | # Carthage/Checkouts
55 |
56 | Carthage/Build
57 |
58 | # fastlane
59 | #
60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
61 | # screenshots whenever they are needed.
62 | # For more information about the recommended setup visit:
63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
64 |
65 | fastlane/report.xml
66 | fastlane/Preview.html
67 | fastlane/screenshots/**/*.png
68 | fastlane/test_output
69 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | }
88 | ],
89 | "info" : {
90 | "version" : 1,
91 | "author" : "xcode"
92 | }
93 | }
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // NewHandGuideDemo
4 | //
5 | // Created by MYH on 2018/1/24.
6 | // Copyright © 2018年 MYH. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // NewHandGuideDemo
4 | //
5 | // Created by MYH on 2018/1/24.
6 | // Copyright © 2018年 MYH. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 | var modes = [MYHGuideInfoModel]()
13 | override func viewDidAppear(_ animated: Bool) {
14 | super.viewDidAppear(animated)
15 | let v1 = UIView.init(frame: CGRect.init(x: 30, y: 60, width: 100, height: 100))
16 | v1.backgroundColor = UIColor.red
17 | self.view.addSubview(v1)
18 | let v3 = UIView.init(frame: CGRect.init(x: 30, y: 10, width: 40, height: 80))
19 | v3.backgroundColor = UIColor.yellow
20 | v1.addSubview(v3)
21 | let v2 = UIView.init(frame: CGRect.init(x: 10, y: 20, width: 40, height: 20))
22 | v2.backgroundColor = UIColor.blue
23 | v3.addSubview(v2)
24 | let v4 = UIView.init(frame: CGRect.init(x: 180, y: 140, width: 60, height: 60))
25 | v4.backgroundColor = UIColor.purple
26 | self.view.addSubview(v4)
27 | let v5 = UIView.init(frame: CGRect.init(x: 300, y: 80, width: 40, height: 40))
28 | v5.backgroundColor = UIColor.gray
29 | v5.layer.cornerRadius = 20
30 | self.view.addSubview(v5)
31 | let v6 = UIView.init(frame: CGRect.init(x: 30, y: 200, width: 60, height: 90))
32 | v6.backgroundColor = UIColor.darkGray
33 | self.view.addSubview(v6)
34 | let v7 = UIView.init(frame: CGRect.init(x: 300, y: 100, width: 20, height: 20))
35 | v7.backgroundColor = UIColor.green
36 | v7.layer.cornerRadius = 10
37 | self.view.addSubview(v7)
38 |
39 | let m1 = MYHGuideInfoModel.init()
40 | let m2 = MYHGuideInfoModel.init()
41 | let m3 = MYHGuideInfoModel.init()
42 | let m4 = MYHGuideInfoModel.init()
43 | let m5 = MYHGuideInfoModel.init()
44 | let m6 = MYHGuideInfoModel.init()
45 | let m7 = MYHGuideInfoModel.init()
46 | m1.text = "你好我好大家好啊!!!!m1"
47 | m2.text = "你好我好大家好啊!!!!m2"
48 | m3.text = "你好我好大家好啊!!!!m3"
49 | m4.text = "你好我好大家好啊!!!!m4"
50 | m5.text = "你好我好大家好啊!!!!m5"
51 | m6.text = "你好我好大家好啊!!!!m6"
52 | m7.text = "你好我好大家好啊!!!!m7"
53 | // 写到这里的主要原因是:viewDidAppear中keyWindows才有值,控件相对屏幕的位置才准确
54 | m1.frameBaseWindow = v1.convert(v1.bounds, to: nil)
55 | m2.frameBaseWindow = v2.convert(v2.bounds, to: nil)
56 | m3.frameBaseWindow = v3.convert(v3.bounds, to: nil)
57 | m4.frameBaseWindow = v4.convert(v4.bounds, to: nil)
58 | m5.frameBaseWindow = v5.convert(v5.bounds, to: nil)
59 | m6.frameBaseWindow = v6.convert(v6.bounds, to: nil)
60 | m7.frameBaseWindow = v7.convert(v7.bounds, to: nil)
61 | m1.textColor = v1.backgroundColor!
62 | m2.textColor = v2.backgroundColor!
63 | m3.textColor = v3.backgroundColor!
64 | m4.textColor = v4.backgroundColor!
65 | m7.textColor = v7.backgroundColor!
66 | m5.maskCornerRadius = 20
67 | m7.maskCornerRadius = 20
68 | modes.append(m1)
69 | modes.append(m2)
70 | modes.append(m3)
71 | modes.append(m4)
72 | modes.append(m5)
73 | modes.append(m6)
74 | modes.append(m7)
75 | }
76 | @objc func show(_ btn : UIButton) {
77 | let gv = MYHGuideMaskView.init(frame: self.view.bounds)
78 | gv.showMask(data: modes)
79 | }
80 | override func viewDidLoad() {
81 | super.viewDidLoad()
82 | // Do any additional setup after loading the view, typically from a nib.
83 |
84 | let btn = UIButton.init(type: UIButtonType.contactAdd)
85 | btn.frame = CGRect.init(x: 0, y: 300, width: 40, height: 40)
86 | btn.addTarget(self, action: #selector(show(_:)), for: UIControlEvents.touchUpInside)
87 | self.view.addSubview(btn)
88 | }
89 |
90 | override func didReceiveMemoryWarning() {
91 | super.didReceiveMemoryWarning()
92 | // Dispose of any resources that can be recreated.
93 | }
94 |
95 |
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo/MYHGuideMaskView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MYHGuideMaskView.swift
3 | // NewHandGuideDemo
4 | //
5 | // Created by MYH on 2018/1/24.
6 | // Copyright © 2018年 MYH. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class MYHGuideMaskView: UIView {
12 | private enum MYHGuideMaskItemRegion : Int {
13 | case leftTop = 0 /*👋 左上方 👋*/
14 | case leftBottom /*👋 左下方 👋*/
15 | case rightTop /*👋 右上方 👋*/
16 | case rightBottom /*👋 右下方 👋*/
17 | }
18 | /*👋 箭头的图片 👋*/
19 | var arrowImage : UIImage? = UIImage.init(named: "guide_arrow") {
20 | didSet{
21 | self.arrowImageView.image = arrowImage
22 | }
23 | }
24 | /*👋 蒙板背景颜色:默认 黑色 👋*/
25 | var maskBackgroundColor : UIColor = UIColor.black {
26 | didSet{
27 | self.maskLayerView.backgroundColor = maskBackgroundColor
28 | }
29 | }
30 | /*👋 蒙板透明度:默认 0.7 👋*/
31 | var maskAlpha : CGFloat = 0.7 {
32 | didSet{
33 | self.maskLayerView.alpha = maskAlpha
34 | }
35 | }
36 |
37 | //MARK: 当前正在进行引导的item下标
38 | private var currentIndex : Int = 0 {
39 | didSet{
40 | if showDatas.count > currentIndex {
41 | self.showItem(data: showDatas[currentIndex])
42 | self.configItemsFrame(data: showDatas[currentIndex])
43 | }
44 | }
45 | }
46 | private var showDatas : [MYHGuideInfoModel] = []
47 | override init(frame: CGRect) {
48 | super.init(frame: UIScreen.main.bounds)
49 | self.setupUI()
50 | }
51 |
52 | private func setupUI() {
53 | self.addSubview(self.maskLayerView)
54 | self.addSubview(self.arrowImageView)
55 | self.addSubview(self.interTextLabel)
56 | self.backgroundColor = UIColor.clear
57 | }
58 |
59 | /// 外部调用,设置提示语的数据源
60 | ///
61 | /// - Parameter data: 提示语的数据源
62 | func showMask(data : [MYHGuideInfoModel]) {
63 | self.showDatas = data
64 | self.currentIndex = 0
65 | UIApplication.shared.keyWindow?.addSubview(self)
66 | self.alpha = 0
67 | UIView.animate(withDuration: 0.3) {
68 | self.alpha = 1
69 | }
70 | }
71 |
72 | /// 显示蒙版
73 | ///
74 | /// - Parameter data: 蒙版数据源
75 | private func showItem(data : MYHGuideInfoModel) {
76 | let formPath = self.maskLayer.path
77 | self.maskLayer.fillColor = UIColor.black.cgColor
78 | // 获取可见区域的路径(开始路径)
79 | let visualPath = UIBezierPath.init(roundedRect: self.fetchVisualFrame(), cornerRadius: data.maskCornerRadius)
80 | // 获取终点路径
81 | let toPath = UIBezierPath.init(rect: self.bounds)
82 | toPath.append(visualPath)
83 | // 遮罩的路径
84 | self.maskLayer.path = toPath.cgPath
85 | self.maskLayer.fillRule = kCAFillRuleEvenOdd
86 | self.layer.mask = self.maskLayer
87 | // 开始移动动画
88 | let anim = CABasicAnimation.init(keyPath: "path")
89 | anim.duration = 0.3
90 | anim.fromValue = formPath
91 | anim.toValue = toPath.cgPath
92 | self.maskLayer.add(anim, forKey: nil)
93 | }
94 |
95 | /// 获取可见的视图的frame
96 | ///
97 | /// - Returns: 可见的视图的frame
98 | private func fetchVisualFrame() -> CGRect {
99 | if self.currentIndex >= self.showDatas.count {
100 | return CGRect.zero
101 | }
102 | var visualRect = self.showDatas[self.currentIndex].frameBaseWindow
103 | visualRect.origin.x += self.showDatas[self.currentIndex].insetEdge.left;
104 | visualRect.origin.y += self.showDatas[self.currentIndex].insetEdge.top;
105 | visualRect.size.width -= (self.showDatas[self.currentIndex].insetEdge.left + self.showDatas[self.currentIndex].insetEdge.right);
106 | visualRect.size.height -= (self.showDatas[self.currentIndex].insetEdge.top + self.showDatas[self.currentIndex].insetEdge.bottom);
107 | return visualRect
108 | }
109 |
110 | /// 设置 items 的 frame
111 | ///
112 | /// - Parameter data: 蒙版数据源
113 | private func configItemsFrame(data : MYHGuideInfoModel) {
114 | self.interTextLabel.text = data.text
115 | self.interTextLabel.textColor = data.textColor
116 | self.interTextLabel.font = data.font
117 | if data.attributeText != nil {
118 | self.interTextLabel.attributedText = data.attributeText
119 | }
120 | // 设置 文字 与 箭头的位置
121 | var textRect = CGRect.zero
122 | var arrowRect = CGRect.zero
123 | let imgSize : CGSize = self.arrowImageView.image?.size ?? CGSize.init(width: 0, height: 0)
124 | let maxWidth = self.bounds.width - data.horizontalInset * 2
125 |
126 | var textSize = CGSize.zero
127 | if let desc = data.text as NSString? {
128 | textSize = desc.boundingRect(with: CGSize.init(width: maxWidth, height: CGFloat.greatestFiniteMagnitude), options: [NSStringDrawingOptions.usesLineFragmentOrigin,NSStringDrawingOptions.usesFontLeading], attributes: [NSAttributedStringKey.font : data.font], context: nil).size
129 | }
130 | var transform = CGAffineTransform.identity
131 | // 获取item的方位
132 | switch self.fetchVisualRegion() {
133 | case .leftTop:
134 | /// 左上
135 | transform = CGAffineTransform.init(scaleX: -1, y: 1)
136 | arrowRect = CGRect.init(x: self.fetchVisualFrame().midX - imgSize.width * 0.5, y: self.fetchVisualFrame().maxY + data.space, width: imgSize.width, height: imgSize.height)
137 | var x : CGFloat = 0
138 | if textSize.width < self.fetchVisualFrame().width {
139 | x = arrowRect.maxX - textSize.width * 0.5
140 | }else{
141 | x = data.horizontalInset
142 | }
143 | textRect = CGRect.init(x: x, y: arrowRect.maxY, width: textSize.width, height: textSize.height)
144 | break
145 | case .rightTop:
146 | /// 右上
147 | arrowRect = CGRect.init(x: self.fetchVisualFrame().midX - imgSize.width * 0.5, y: self.fetchVisualFrame().maxY + data.space, width: imgSize.width, height: imgSize.height)
148 | var x : CGFloat = 0
149 | if textSize.width < self.fetchVisualFrame().width {
150 | x = arrowRect.minX - textSize.width * 0.5
151 | } else {
152 | x = data.horizontalInset + maxWidth - textSize.width
153 | }
154 | textRect = CGRect.init(x: x, y: arrowRect.maxY, width: textSize.width, height: textSize.height)
155 | break
156 | case .leftBottom:
157 | /// 左下
158 | transform = CGAffineTransform.init(scaleX: -1, y: -1)
159 | arrowRect = CGRect.init(x: self.fetchVisualFrame().midX - imgSize.width * 0.5, y: self.fetchVisualFrame().minY - data.space - imgSize.height, width: imgSize.width, height: imgSize.height)
160 | var x : CGFloat = 0
161 | if textSize.width < self.fetchVisualFrame().width {
162 | x = arrowRect.maxX - textSize.width * 0.5
163 | } else {
164 | x = data.horizontalInset
165 | }
166 | textRect = CGRect.init(x: x, y: arrowRect.minY - data.space - textSize.height, width: textSize.width, height: textSize.height)
167 | break
168 | case .rightBottom:
169 | /// 右下
170 | transform = CGAffineTransform.init(scaleX: 1, y: -1)
171 | arrowRect = CGRect.init(x: self.fetchVisualFrame().midX - imgSize.width * 0.5, y: self.fetchVisualFrame().maxY - data.space - imgSize.height, width: imgSize.width, height: imgSize.height)
172 | var x : CGFloat = 0
173 | if textSize.width < self.fetchVisualFrame().width {
174 | x = arrowRect.minX - textSize.width * 0.5
175 | } else {
176 | x = data.horizontalInset + maxWidth - textSize.width
177 | }
178 | textRect = CGRect.init(x: x, y: arrowRect.minY - data.space - imgSize.height, width: textSize.width, height: textSize.height)
179 | break
180 | }
181 |
182 | UIView.animate(withDuration: 0.3) {
183 | self.arrowImageView.transform = transform
184 | self.arrowImageView.frame = arrowRect
185 | self.interTextLabel.frame = textRect
186 | }
187 | }
188 |
189 | /// 获取可见区域的方位
190 | ///
191 | /// - Returns: 可见区域的方位
192 | private func fetchVisualRegion() -> MYHGuideMaskItemRegion {
193 | /// 可见区域的中心坐标
194 | let visualCenter = CGPoint.init(x:self.fetchVisualFrame().midX, y: self.fetchVisualFrame().midY)
195 | /// self.view 的中心坐标
196 | let viewCenter = CGPoint.init(x:self.bounds.midX, y: self.bounds.midY)
197 | if ((visualCenter.x <= viewCenter.x) &&
198 | (visualCenter.y <= viewCenter.y))
199 | {
200 | /// 当前显示的视图在左上角
201 | return MYHGuideMaskItemRegion.leftTop
202 | }
203 | if ((visualCenter.x > viewCenter.x) &&
204 | (visualCenter.y <= viewCenter.y))
205 | {
206 | /// 当前显示的视图在右上角
207 | return MYHGuideMaskItemRegion.rightTop
208 | }
209 | if ((visualCenter.x <= viewCenter.x) &&
210 | (visualCenter.y > viewCenter.y))
211 | {
212 | /// 当前显示的视图在左下角
213 | return MYHGuideMaskItemRegion.leftBottom
214 | }
215 | /// 当前显示的视图在右下角
216 | return MYHGuideMaskItemRegion.rightBottom
217 | }
218 | //MARK: 蒙版
219 | private lazy var maskLayerView: UIView = {
220 | var mlv = UIView.init(frame: self.bounds)
221 | mlv.backgroundColor = UIColor.black
222 | mlv.alpha = maskAlpha
223 | return mlv
224 | }()
225 | private lazy var maskLayer: CAShapeLayer = {
226 | var ml = CAShapeLayer()
227 | ml.frame = self.bounds
228 | return ml
229 | }()
230 | //MARK: 描述的label
231 | lazy var interTextLabel: UILabel = {
232 | var lb = UILabel.init()
233 | lb.numberOfLines = 0
234 | lb.textColor = UIColor.white
235 | lb.font = UIFont.systemFont(ofSize: 13)
236 | return lb
237 | }()
238 | //MARK: 箭头图片
239 | private lazy var arrowImageView: UIImageView = {
240 | var img = UIImageView.init()
241 | img.image = UIImage.init(named: "guide_arrow")
242 | return img
243 | }()
244 | required init?(coder aDecoder: NSCoder) {
245 | fatalError("init(coder:) has not been implemented")
246 | }
247 | override func touchesBegan(_ touches: Set, with event: UIEvent?) {
248 | if self.currentIndex < self.showDatas.count - 1 {
249 | self.currentIndex = self.currentIndex + 1
250 | } else {
251 | UIView.animate(withDuration: 0.3, animations: {
252 | self.alpha = 0
253 | }, completion: { (finish) in
254 | self.removeFromSuperview()
255 | })
256 | }
257 | }
258 | }
259 | /*👋 每一个提示的属性 👋*/
260 | class MYHGuideInfoModel: NSObject {
261 | /*👋 每个item的文字 👋*/
262 | var text : String?
263 | /*👋 每个item的文字颜色 👋*/
264 | var textColor : UIColor = UIColor.white
265 | /*👋 每个item的属性字符串 👋*/
266 | var attributeText : NSAttributedString?
267 | /*👋 每个item文字的大小 👋*/
268 | var font = UIFont.systemFont(ofSize: 13)
269 | /*👋 每个 item 的 view 蒙板的圆角:默认为 5 👋*/
270 | var maskCornerRadius : CGFloat = 5
271 | /*👋 每个 item 的 view 与蒙板的边距:默认 (-8, -8, -8, -8) 👋*/
272 | var insetEdge = UIEdgeInsetsMake(-8, -8, -8, -8)
273 | /*👋 每个 item 的子视图(当前介绍的子视图、箭头、描述文字)之间的间距:默认为 20 👋*/
274 | var space : CGFloat = 20
275 | /*👋 每个 item 的文字与左右边框间的距离:默认为 50 👋*/
276 | var horizontalInset : CGFloat = 50
277 | /*👋 相对window的frame 👋*/
278 | var frameBaseWindow = CGRect.zero
279 | }
280 |
--------------------------------------------------------------------------------
/NewHandGuideDemo/NewHandGuideDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 48;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 134CA7502018545B003EF78E /* guide_arrow@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 134CA74F2018545B003EF78E /* guide_arrow@3x.png */; };
11 | 137B260620181A3F009AC57F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 137B260520181A3F009AC57F /* AppDelegate.swift */; };
12 | 137B260820181A3F009AC57F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 137B260720181A3F009AC57F /* ViewController.swift */; };
13 | 137B260B20181A3F009AC57F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 137B260920181A3F009AC57F /* Main.storyboard */; };
14 | 137B260D20181A3F009AC57F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 137B260C20181A3F009AC57F /* Assets.xcassets */; };
15 | 137B261020181A3F009AC57F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 137B260E20181A3F009AC57F /* LaunchScreen.storyboard */; };
16 | 137B261820181A7B009AC57F /* MYHGuideMaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 137B261720181A7B009AC57F /* MYHGuideMaskView.swift */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXFileReference section */
20 | 134CA74F2018545B003EF78E /* guide_arrow@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "guide_arrow@3x.png"; sourceTree = ""; };
21 | 137B260220181A3E009AC57F /* NewHandGuideDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NewHandGuideDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
22 | 137B260520181A3F009AC57F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
23 | 137B260720181A3F009AC57F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
24 | 137B260A20181A3F009AC57F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
25 | 137B260C20181A3F009AC57F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
26 | 137B260F20181A3F009AC57F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
27 | 137B261120181A40009AC57F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
28 | 137B261720181A7B009AC57F /* MYHGuideMaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MYHGuideMaskView.swift; sourceTree = ""; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 137B25FF20181A3E009AC57F /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | );
37 | runOnlyForDeploymentPostprocessing = 0;
38 | };
39 | /* End PBXFrameworksBuildPhase section */
40 |
41 | /* Begin PBXGroup section */
42 | 137B25F920181A3E009AC57F = {
43 | isa = PBXGroup;
44 | children = (
45 | 137B260420181A3E009AC57F /* NewHandGuideDemo */,
46 | 137B260320181A3E009AC57F /* Products */,
47 | );
48 | sourceTree = "";
49 | };
50 | 137B260320181A3E009AC57F /* Products */ = {
51 | isa = PBXGroup;
52 | children = (
53 | 137B260220181A3E009AC57F /* NewHandGuideDemo.app */,
54 | );
55 | name = Products;
56 | sourceTree = "";
57 | };
58 | 137B260420181A3E009AC57F /* NewHandGuideDemo */ = {
59 | isa = PBXGroup;
60 | children = (
61 | 137B260520181A3F009AC57F /* AppDelegate.swift */,
62 | 137B260720181A3F009AC57F /* ViewController.swift */,
63 | 137B261720181A7B009AC57F /* MYHGuideMaskView.swift */,
64 | 134CA74F2018545B003EF78E /* guide_arrow@3x.png */,
65 | 137B260920181A3F009AC57F /* Main.storyboard */,
66 | 137B260C20181A3F009AC57F /* Assets.xcassets */,
67 | 137B260E20181A3F009AC57F /* LaunchScreen.storyboard */,
68 | 137B261120181A40009AC57F /* Info.plist */,
69 | );
70 | path = NewHandGuideDemo;
71 | sourceTree = "";
72 | };
73 | /* End PBXGroup section */
74 |
75 | /* Begin PBXNativeTarget section */
76 | 137B260120181A3E009AC57F /* NewHandGuideDemo */ = {
77 | isa = PBXNativeTarget;
78 | buildConfigurationList = 137B261420181A40009AC57F /* Build configuration list for PBXNativeTarget "NewHandGuideDemo" */;
79 | buildPhases = (
80 | 137B25FE20181A3E009AC57F /* Sources */,
81 | 137B25FF20181A3E009AC57F /* Frameworks */,
82 | 137B260020181A3E009AC57F /* Resources */,
83 | );
84 | buildRules = (
85 | );
86 | dependencies = (
87 | );
88 | name = NewHandGuideDemo;
89 | productName = NewHandGuideDemo;
90 | productReference = 137B260220181A3E009AC57F /* NewHandGuideDemo.app */;
91 | productType = "com.apple.product-type.application";
92 | };
93 | /* End PBXNativeTarget section */
94 |
95 | /* Begin PBXProject section */
96 | 137B25FA20181A3E009AC57F /* Project object */ = {
97 | isa = PBXProject;
98 | attributes = {
99 | LastSwiftUpdateCheck = 0920;
100 | LastUpgradeCheck = 0920;
101 | ORGANIZATIONNAME = MYH;
102 | TargetAttributes = {
103 | 137B260120181A3E009AC57F = {
104 | CreatedOnToolsVersion = 9.2;
105 | ProvisioningStyle = Automatic;
106 | };
107 | };
108 | };
109 | buildConfigurationList = 137B25FD20181A3E009AC57F /* Build configuration list for PBXProject "NewHandGuideDemo" */;
110 | compatibilityVersion = "Xcode 8.0";
111 | developmentRegion = en;
112 | hasScannedForEncodings = 0;
113 | knownRegions = (
114 | en,
115 | Base,
116 | );
117 | mainGroup = 137B25F920181A3E009AC57F;
118 | productRefGroup = 137B260320181A3E009AC57F /* Products */;
119 | projectDirPath = "";
120 | projectRoot = "";
121 | targets = (
122 | 137B260120181A3E009AC57F /* NewHandGuideDemo */,
123 | );
124 | };
125 | /* End PBXProject section */
126 |
127 | /* Begin PBXResourcesBuildPhase section */
128 | 137B260020181A3E009AC57F /* Resources */ = {
129 | isa = PBXResourcesBuildPhase;
130 | buildActionMask = 2147483647;
131 | files = (
132 | 134CA7502018545B003EF78E /* guide_arrow@3x.png in Resources */,
133 | 137B261020181A3F009AC57F /* LaunchScreen.storyboard in Resources */,
134 | 137B260D20181A3F009AC57F /* Assets.xcassets in Resources */,
135 | 137B260B20181A3F009AC57F /* Main.storyboard in Resources */,
136 | );
137 | runOnlyForDeploymentPostprocessing = 0;
138 | };
139 | /* End PBXResourcesBuildPhase section */
140 |
141 | /* Begin PBXSourcesBuildPhase section */
142 | 137B25FE20181A3E009AC57F /* Sources */ = {
143 | isa = PBXSourcesBuildPhase;
144 | buildActionMask = 2147483647;
145 | files = (
146 | 137B260820181A3F009AC57F /* ViewController.swift in Sources */,
147 | 137B261820181A7B009AC57F /* MYHGuideMaskView.swift in Sources */,
148 | 137B260620181A3F009AC57F /* AppDelegate.swift in Sources */,
149 | );
150 | runOnlyForDeploymentPostprocessing = 0;
151 | };
152 | /* End PBXSourcesBuildPhase section */
153 |
154 | /* Begin PBXVariantGroup section */
155 | 137B260920181A3F009AC57F /* Main.storyboard */ = {
156 | isa = PBXVariantGroup;
157 | children = (
158 | 137B260A20181A3F009AC57F /* Base */,
159 | );
160 | name = Main.storyboard;
161 | sourceTree = "";
162 | };
163 | 137B260E20181A3F009AC57F /* LaunchScreen.storyboard */ = {
164 | isa = PBXVariantGroup;
165 | children = (
166 | 137B260F20181A3F009AC57F /* Base */,
167 | );
168 | name = LaunchScreen.storyboard;
169 | sourceTree = "";
170 | };
171 | /* End PBXVariantGroup section */
172 |
173 | /* Begin XCBuildConfiguration section */
174 | 137B261220181A40009AC57F /* Debug */ = {
175 | isa = XCBuildConfiguration;
176 | buildSettings = {
177 | ALWAYS_SEARCH_USER_PATHS = NO;
178 | CLANG_ANALYZER_NONNULL = YES;
179 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
181 | CLANG_CXX_LIBRARY = "libc++";
182 | CLANG_ENABLE_MODULES = YES;
183 | CLANG_ENABLE_OBJC_ARC = YES;
184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
185 | CLANG_WARN_BOOL_CONVERSION = YES;
186 | CLANG_WARN_COMMA = YES;
187 | CLANG_WARN_CONSTANT_CONVERSION = YES;
188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
189 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
190 | CLANG_WARN_EMPTY_BODY = YES;
191 | CLANG_WARN_ENUM_CONVERSION = YES;
192 | CLANG_WARN_INFINITE_RECURSION = YES;
193 | CLANG_WARN_INT_CONVERSION = YES;
194 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
195 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
197 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
198 | CLANG_WARN_STRICT_PROTOTYPES = YES;
199 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
200 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
201 | CLANG_WARN_UNREACHABLE_CODE = YES;
202 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
203 | CODE_SIGN_IDENTITY = "iPhone Developer";
204 | COPY_PHASE_STRIP = NO;
205 | DEBUG_INFORMATION_FORMAT = dwarf;
206 | ENABLE_STRICT_OBJC_MSGSEND = YES;
207 | ENABLE_TESTABILITY = YES;
208 | GCC_C_LANGUAGE_STANDARD = gnu11;
209 | GCC_DYNAMIC_NO_PIC = NO;
210 | GCC_NO_COMMON_BLOCKS = YES;
211 | GCC_OPTIMIZATION_LEVEL = 0;
212 | GCC_PREPROCESSOR_DEFINITIONS = (
213 | "DEBUG=1",
214 | "$(inherited)",
215 | );
216 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
217 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
218 | GCC_WARN_UNDECLARED_SELECTOR = YES;
219 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
220 | GCC_WARN_UNUSED_FUNCTION = YES;
221 | GCC_WARN_UNUSED_VARIABLE = YES;
222 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
223 | MTL_ENABLE_DEBUG_INFO = YES;
224 | ONLY_ACTIVE_ARCH = YES;
225 | SDKROOT = iphoneos;
226 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
227 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
228 | };
229 | name = Debug;
230 | };
231 | 137B261320181A40009AC57F /* Release */ = {
232 | isa = XCBuildConfiguration;
233 | buildSettings = {
234 | ALWAYS_SEARCH_USER_PATHS = NO;
235 | CLANG_ANALYZER_NONNULL = YES;
236 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
237 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
238 | CLANG_CXX_LIBRARY = "libc++";
239 | CLANG_ENABLE_MODULES = YES;
240 | CLANG_ENABLE_OBJC_ARC = YES;
241 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
242 | CLANG_WARN_BOOL_CONVERSION = YES;
243 | CLANG_WARN_COMMA = YES;
244 | CLANG_WARN_CONSTANT_CONVERSION = YES;
245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
247 | CLANG_WARN_EMPTY_BODY = YES;
248 | CLANG_WARN_ENUM_CONVERSION = YES;
249 | CLANG_WARN_INFINITE_RECURSION = YES;
250 | CLANG_WARN_INT_CONVERSION = YES;
251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
252 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
254 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
255 | CLANG_WARN_STRICT_PROTOTYPES = YES;
256 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
257 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
258 | CLANG_WARN_UNREACHABLE_CODE = YES;
259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
260 | CODE_SIGN_IDENTITY = "iPhone Developer";
261 | COPY_PHASE_STRIP = NO;
262 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
263 | ENABLE_NS_ASSERTIONS = NO;
264 | ENABLE_STRICT_OBJC_MSGSEND = YES;
265 | GCC_C_LANGUAGE_STANDARD = gnu11;
266 | GCC_NO_COMMON_BLOCKS = YES;
267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
269 | GCC_WARN_UNDECLARED_SELECTOR = YES;
270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
271 | GCC_WARN_UNUSED_FUNCTION = YES;
272 | GCC_WARN_UNUSED_VARIABLE = YES;
273 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
274 | MTL_ENABLE_DEBUG_INFO = NO;
275 | SDKROOT = iphoneos;
276 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
277 | VALIDATE_PRODUCT = YES;
278 | };
279 | name = Release;
280 | };
281 | 137B261520181A40009AC57F /* Debug */ = {
282 | isa = XCBuildConfiguration;
283 | buildSettings = {
284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
285 | CODE_SIGN_STYLE = Automatic;
286 | DEVELOPMENT_TEAM = YC65XR2WDU;
287 | INFOPLIST_FILE = NewHandGuideDemo/Info.plist;
288 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
290 | PRODUCT_BUNDLE_IDENTIFIER = com.skyu.myh.NewHandGuideDemo;
291 | PRODUCT_NAME = "$(TARGET_NAME)";
292 | SWIFT_VERSION = 4.0;
293 | TARGETED_DEVICE_FAMILY = "1,2";
294 | };
295 | name = Debug;
296 | };
297 | 137B261620181A40009AC57F /* Release */ = {
298 | isa = XCBuildConfiguration;
299 | buildSettings = {
300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
301 | CODE_SIGN_STYLE = Automatic;
302 | DEVELOPMENT_TEAM = YC65XR2WDU;
303 | INFOPLIST_FILE = NewHandGuideDemo/Info.plist;
304 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
305 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
306 | PRODUCT_BUNDLE_IDENTIFIER = com.skyu.myh.NewHandGuideDemo;
307 | PRODUCT_NAME = "$(TARGET_NAME)";
308 | SWIFT_VERSION = 4.0;
309 | TARGETED_DEVICE_FAMILY = "1,2";
310 | };
311 | name = Release;
312 | };
313 | /* End XCBuildConfiguration section */
314 |
315 | /* Begin XCConfigurationList section */
316 | 137B25FD20181A3E009AC57F /* Build configuration list for PBXProject "NewHandGuideDemo" */ = {
317 | isa = XCConfigurationList;
318 | buildConfigurations = (
319 | 137B261220181A40009AC57F /* Debug */,
320 | 137B261320181A40009AC57F /* Release */,
321 | );
322 | defaultConfigurationIsVisible = 0;
323 | defaultConfigurationName = Release;
324 | };
325 | 137B261420181A40009AC57F /* Build configuration list for PBXNativeTarget "NewHandGuideDemo" */ = {
326 | isa = XCConfigurationList;
327 | buildConfigurations = (
328 | 137B261520181A40009AC57F /* Debug */,
329 | 137B261620181A40009AC57F /* Release */,
330 | );
331 | defaultConfigurationIsVisible = 0;
332 | defaultConfigurationName = Release;
333 | };
334 | /* End XCConfigurationList section */
335 | };
336 | rootObject = 137B25FA20181A3E009AC57F /* Project object */;
337 | }
338 |
--------------------------------------------------------------------------------