SomeInnerView
SomeInnerView是一个UIView,可以让您使用另一个图像的一部分选择图像的一部分。例如,这可以是同一张图片。例如,我只是在背景图像上方添加了一个模糊效果视图,当选择的部分是一个没有效果的图像时。选择的结果保存在属性x、y、right、bottom中。它们表示坐标矩形(范围从0到1)
innerView = InnerView()
innerView.backgroundColor = .black
innerView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(innerView)
innerView.leadingAnchor.constraint (equalTo: self.view.leadingAnchor).isActive = true
innerView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
innerView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
innerView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
guard let sourceImage = UIImage(named: "image") else { return }
innerView.mainImage = sourceImage
innerView.background.backgroundColor = .red
let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
innerView.background.addSubview(blurEffectView)
blurEffectView.leadingAnchor.constraint(equalTo: innerView.background.leadingAnchor).isActive = true
blurEffectView.trailingAnchor.constraint(equalTo: innerView.background.trailingAnchor).isActive = true
blurEffectView.topAnchor.constraint(equalTo: innerView.background.topAnchor).isActive = true
blurEffectView.bottomAnchor.constraint(equalTo: innerView.background.bottomAnchor).isActive = true
innerView.selectionView.backgroundColor = .white
innerView.secondaryImage = sourceImage
innerView.x = 0.25
innerView.y = 0.25
innerView.bottom = 0.7
innerView.right = 0.7
innerView.isSelectionInitialized = true
innerView.selectionView.layer.cornerRadius = 45
innerView.selectionView.layer.masksToBounds = true
要显示选择视图,您需要设置一个可见矩形并调用
innerView.isSelectionInitialized = true
将此设置为false将隐藏选择视图
您可以通过设置属性x、y、bottom、right来移动选择。为了允许用户与选择视图交互:
innerView.selectionView.isUserInteractionEnabled = true
为了将选择视图固定在图像的一部分上
innerView.isSelectionFixed = true
如何使用
pod "SomeInnerView"
import SomeInnerView