我在设置subImageViews时无法显示其区域中具有alpha 1的父ImageView,但是我周围的所有Alpha值都必须为0.25。你有什么想法?我试图通过View(现在是ImageView)来实现,但是找不到解决方案。中间的16个正方形需要显示清晰的图像,在按下“开始”按钮后,他们将裁剪其区域并将其发送给其他VC。感谢您的帮助
所以我一直在努力并找到解决方案(也感谢@iOSDev链接到本文)。
如果有人需要类似的东西,这里是:
@IBOutlet weak var alphaView: UIView!
@IBOutlet weak var pickedImage: UIImageView!
@IBOutlet weak var bigStackView: UIStackView!
override func viewWillAppear(_ animated: Bool) {
pickedImage.image = imagePicked
// Set white background color with custom alpha
alphaView.backgroundColor = UIColor(white: 255/255, alpha: 0.85)
// Create the initial layer from the stackView bounds.
let maskLayer = CAShapeLayer()
maskLayer.frame = alphaView.bounds
// Create the frame to cover whole stackView
let rect = CGRect(
x: bigStackView.frame.minX,
y: bigStackView.frame.minY,
width: bigStackView.bounds.width,
height: bigStackView.bounds.height)
// Create the path
let path = UIBezierPath(rect: alphaView.bounds)
maskLayer.fillRule = CAShapeLayerFillRule.evenOdd
// Append the framer to the path so that it is subtracted
path.append(UIBezierPath(rect: rect))
maskLayer.path = path.cgPath
// Set the mask of the alphaview
alphaView.layer.mask = maskLayer
}
pickedImage是由aplhaView覆盖的背景图像视图,仅用于使其模糊,并且bigStackView在中间为16个正方形以确定所需正方形的位置。还可以使用显式的CGPoint和CGSize值。