iOS新手引导--GuideImageView(一)
iOS新手引导--GuideImageView(二)
iOS新手引导--GuideImageView(三)
在上一篇中介绍了GuideImageView的基本用法,本篇讲讲实现遇到的问题。
一、思路
首先要看到本质才能解决问题。
如下图:
假设高亮区域 相对屏幕 坐标为maskViewRect
将图片imageView的坐标imageViewRect
和maskViewRect
的中心区域对齐,便能将引导图覆盖到屏幕上了。

对于X坐标:
imageViewRect.x + maskImageRect.x + maskImageSize.width/2.0 = maskViewRect.x + maskViewRect.width/2.0
对于Y坐标:
imageViewRect.y + maskImageRect.y + maskImageSize.height/2.0 = maskViewRect.y + maskViewRect.height/2.0
imageViewRect的大小为图片大小imageSize
,求出 imageViewRect.x
、imageViewRect.y
,则imageView的坐标系就知道了~
二、难点
对与底部的UITabBar
是通过tabBarItem
来设置样式的。
为了获取“tabBarItem”的坐标,得另寻方法。
点进UITabBar
,发现其继承于UIView
。
通过log
or查看视图层级
or 断点
调试
会发现tabBarItem
实际是生成了UITabBarButton
这个私有类的视图。

知道这个,将
UITabBar
的UITabBarButton
按照坐标x
的大小存入数组,便能根据下标Index获取到位置了!
GuideImageView讲解到此为止,更多细节请参考demo~
github:https://github.com/woaiyouxi0803/GuideImageView 好用欢迎点🌟Star~
网友评论