Like the title states, I'm having trouble checking if a button intersects with a CAShapeLayer. Right now I have a button that is being moved around via a UIPanGestureRecognizer. When it's let go, I want to check if it's on top of a certain color on this wheel that I have: Simulator View
The colors are being generated as CAShapeLayers with code like this:
let path1 = UIBezierPath() path1.addArc(withCenter: center, radius: 50, startAngle: CGFloat.pi/4 + 0.1, endAngle: CGFloat.pi*3/4 - 0.1, clockwise: true) path1.addArc(withCenter: center, radius: 125, startAngle: CGFloat.pi*3/4 - 0.05, endAngle: CGFloat.pi/4 + 0.05, clockwise: false) blueCircle.path = path1.cgPath blueCircle.fillColor = UIColor(red: 0, green: 143/255, blue: 208/255, alpha: 1).cgColor self.view.layer.addSublayer(blueCircle) where blueCircle is a CAShapeLayer.
I have code that checks if my "recognizer" (UIPanGestureRecognizer) overlaps on release that looks something like this:
if recognizer.view!.frame.intersects(blueCircle.frame) { print("Blue overlap") } but I suspect it always returns false because they aren't in the same "layer". I tried a variety of things including using bounds instead of frames and trying to convert using the center of the gesture recognizer but it doesn't seem to work properly.
https://stackoverflow.com/questions/66434150/swift-how-to-check-if-a-cashapelayer-intersects-with-a-button-uiview March 02, 2021 at 02:07PM
没有评论:
发表评论