Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中的圆形UIView中获取CGPoint?_Ios_Swift - Fatal编程技术网

如何在iOS中的圆形UIView中获取CGPoint?

如何在iOS中的圆形UIView中获取CGPoint?,ios,swift,Ios,Swift,我已经使用UIBezierPath和setcorneradius设置了UIView角半径。检查以下代码: func roundCorners(cornerRadius: Double) { let path = UIBezierPath(roundedRect: self.puttingView.bounds, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight], cornerRadii: CGS

我已经使用
UIBezierPath
setcorneradius
设置了
UIView
角半径。检查以下代码:

func roundCorners(cornerRadius: Double) {
        let path = UIBezierPath(roundedRect: self.puttingView.bounds, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
        let maskLayer = CAShapeLayer()
        maskLayer.frame = self.puttingView.bounds
        maskLayer.path = path.cgPath
        self.puttingView.layer.mask = maskLayer
    }
现在,当我尝试单击外部
ui视图
角半径时,我将
ui动作识别器
设置为打开
ui视图
,并且可以单击
ui视图
。 所以我不想得到
CGPoint
外角半径。

试试这个:

@objc func tapped(_ gesture: UITapGestureRecognizer) {
        let loc:CGPoint = gesture.location(in: gesture.view)
        if let layer = puttingView.layer.mask, layer.bounds.contains(loc){
            print("inside")
        }
    }
试试这个:

@objc func tapped(_ gesture: UITapGestureRecognizer) {
        let loc:CGPoint = gesture.location(in: gesture.view)
        if let layer = puttingView.layer.mask, layer.bounds.contains(loc){
            print("inside")
        }
    }

您可能需要实现这一点

func point(inside point: CGPoint, with event: UIEvent?) -> Bool

您可能需要实现这一点

func point(inside point: CGPoint, with event: UIEvent?) -> Bool

首先,将您的
控制器
UIgestureRecognitizerDelegate
相一致,并实施
gestureRecognitizer(u:shouldReceive:)
方法

如果触摸屏位于
遮罩内,则返回
true
,否则返回
false

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    let frame = self.puttingView.layer.mask?.bounds
    let location = touch.location(in: self.puttingView)
    if frame?.contains(location) ?? false {
        return true
    }
    return false
}
不要忘记设置要添加到
puttingView
手势识别器的
委托
,即

let gesture = UITapGestureRecognizer(target: self, action: #selector(viewTapped(_:)))
gesture.delegate = self //here......
self.puttingView.addGestureRecognizer(gesture)

首先,将您的
控制器
UIgestureRecognitizerDelegate
相一致,并实施
gestureRecognitizer(u:shouldReceive:)
方法

如果触摸屏位于
遮罩内,则返回
true
,否则返回
false

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    let frame = self.puttingView.layer.mask?.bounds
    let location = touch.location(in: self.puttingView)
    if frame?.contains(location) ?? false {
        return true
    }
    return false
}
不要忘记设置要添加到
puttingView
手势识别器的
委托
,即

let gesture = UITapGestureRecognizer(target: self, action: #selector(viewTapped(_:)))
gesture.delegate = self //here......
self.puttingView.addGestureRecognizer(gesture)

@iOS,请记录loc的值和层的边界,然后让我know@iOS,请记录loc的值和层的边界,并让我知道