StackOverFlow 社区您好,
我有一个标准的 UIBezierPath 如下:
let π:CGFloat = CGFloat(M_PI)
override func drawRect(rect: CGRect){
let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
let radius: CGFloat = max(self.bounds.width, self.bounds.height) - 60
let arcWidth: CGFloat = 40
var startAngle: CGFloat = 0
var endAngle: CGFloat = (2 * π)
var path = UIBezierPath(arcCenter: center,
radius: radius/2 - arcWidth/2,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
path.lineWidth = arcWidth
UIColor.redColor().setStroke()
path.stroke()
}
这会产生一个非常简单的弧线。很简单,我希望能够在应用程序运行时选择/按下此弧线(如按钮),并能够触发操作。有什么办法可以做到这一点吗?
谢谢!
最佳答案
您可以为自定义 View 创建一个Outlet
,并在该自定义 View 中添加tapgesture
,如下所示:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var arcView: customView!
override func viewDidLoad() {
super.viewDidLoad()
var tapGesture = UITapGestureRecognizer(target: self, action: "SomeMethod")
self.arcView.addGestureRecognizer(tapGesture)
}
func SomeMethod(){
//change label text
}
}
现在,只要您点击 arcView
,您的 SomeMethod
就会调用。您可以在该方法中更改标签文本。
有关更多信息,请参阅 THIS您可以在教程中找到如何检测贝塞尔曲线路径上的触摸。
关于ios - 如何使 UIBezierPath 可选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32132677/