1. One way
The easiest way to do this is to have the UI create various sizes for the screen and use them directly
2. 2
UIBezierPath draw + image
1. Create a transparent View GuideView that fills the screen
2. Create a background view [bgView] and place it on GuideView
3. Start drawing transparent frames and set bgView
4. Place pictures
Key BSLPath method
import UIKit
class KWGuide1View: KWView {
override func kw_setupViews() {
super.kw_setupViews()
frame = CGRect(x: 0.y: 0.width: KScreenWidth, height: KScreenHeight)
backgroundColor = .clear
self.BSLPath()
}
override func kw_setupLayouts() {
super.kw_setupLayouts()
}
func BSLPath() {
let bgView = UIView(frame: CGRect(x: 0.y: 0.width: KScreenWidth, height: KScreenHeight))
addSubview(bgView)
// The whole background
let bsl = UIBezierPath.init(rect: CGRect(x: 0.y: 0.width: KScreenWidth, height: KScreenHeight))
/ / transparent box
let bslClear = UIBezierPath(roundedRect: CGRect(x: KScreenWidth/4*3.y: KScreenHeight-KTabBarHeight-KHomeIndicatorHeight+KHomeIndicatorHeight, width: KScreenWidth/4.height: KTabBarHeight-KHomeIndicatorHeight),cornerRadius:5).reversing()
bsl.append(bslClear)
let layer = CAShapeLayer()
layer.fillColor = UIColor.init(r: 0.g: 0.b: 0.alpha: 0.7).cgColor
layer.path = bsl.cgPath
bgView.layer.addSublayer(layer)
addSubview(imgv)
imgv.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: KScreenWidth-50.height: (KScreenWidth-50) /336*487 ))
make.right.equalTo(-15)
make.bottom.equalTo(-KTabBarHeight)
}
bgView.kw.tapAtion { _ in
self.removeFromSuperview()
letv2 = KWGuide2View() UIApplication.shared.keyWindow? .addSubview(v2) } } private lazyvar imgv:UIImageView = {
let img = UIImageView()
img.image = UIImage(named: "ic_yindao_1")
img.contentMode = .scaleToFill
return img
}()
}
Copy the code