如何循环遍历 UIBezierPath swift 中的点?
How to loop through point in UIBezierPath swift?
如何遍历圆形 UIBezierPath 坐标,以便当用户在屏幕上移动手指时,我可以在圆形路径上移动点对象? (有点像虚拟密码锁)
let blueDotCategoryName = "blue"
var blueDot = SKSpriteNode()
//...
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
let node = self.nodeAtPoint(touchLocation)
if node.name == blueDotCategoryName {
fingerIsOn = true
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
if fingerIsOn {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
let prevTouchLocation = touch.previousLocationInNode(self)
let blueDot = self.childNodeWithName(blueDotCategoryName) as SKSpriteNode
// var newPosition = coordinates in circle UIBezierPath
// blueDot.position = ...
}
/*
var circle = UIBezierPath()
circle.addArcWithCenter(CGPoint(x: 0, y: 0), radius: (self.frame.width / 6.7), startAngle: 0, endAngle: 360, clockwise: true)
*/
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
fingerIsOn = false
}
没有为您执行此操作的内置方法,因此您必须自己编写。如果将贝塞尔曲线路径创建为一系列线段可能会更容易(如果它们彼此足够接近,它将与原始路径无法区分)。
话虽如此,鉴于您的描述(“虚拟组合锁”),我想知道是否有一些第三方复杂的手势识别器可以为您简化整个过程:
Unistroke Recognizer - 复杂手势的单笔识别器。
您也可以考虑 GLGestureRecognizer
,一个 Objective-C 实现。
$N Multistroke Recognizer - $1 Unistroke Recognizer
的多笔画版本
这在 Complex Gesture Recognition in iOS 中有详细讨论。
这些可能会启动你的努力。
如何遍历圆形 UIBezierPath 坐标,以便当用户在屏幕上移动手指时,我可以在圆形路径上移动点对象? (有点像虚拟密码锁)
let blueDotCategoryName = "blue"
var blueDot = SKSpriteNode()
//...
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
let node = self.nodeAtPoint(touchLocation)
if node.name == blueDotCategoryName {
fingerIsOn = true
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
if fingerIsOn {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
let prevTouchLocation = touch.previousLocationInNode(self)
let blueDot = self.childNodeWithName(blueDotCategoryName) as SKSpriteNode
// var newPosition = coordinates in circle UIBezierPath
// blueDot.position = ...
}
/*
var circle = UIBezierPath()
circle.addArcWithCenter(CGPoint(x: 0, y: 0), radius: (self.frame.width / 6.7), startAngle: 0, endAngle: 360, clockwise: true)
*/
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
fingerIsOn = false
}
没有为您执行此操作的内置方法,因此您必须自己编写。如果将贝塞尔曲线路径创建为一系列线段可能会更容易(如果它们彼此足够接近,它将与原始路径无法区分)。
话虽如此,鉴于您的描述(“虚拟组合锁”),我想知道是否有一些第三方复杂的手势识别器可以为您简化整个过程:
Unistroke Recognizer - 复杂手势的单笔识别器。
您也可以考虑
GLGestureRecognizer
,一个 Objective-C 实现。$N Multistroke Recognizer - $1 Unistroke Recognizer
的多笔画版本这在 Complex Gesture Recognition in iOS 中有详细讨论。
这些可能会启动你的努力。