0
내가 배열 저장소에있는 모든 첫 번째 터치 마지막 터치를 , 연결된 모든 라인에 대해 신속캐치 신속하고 핵심 그래픽
드로잉 응용 프로그램의를 사용하여 그리기 응용 프로그램을 만드는 중이라서, 그래서 내가 원하는에 지점
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var drawingPlace: UIImageView!
var startTouch : CGPoint?
var finalTouch : CGPoint?
var storePoints : [CGPoint] = [] // this will store the first touch and the last touch
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
let location = touch?.location(in: drawingPlace) //
if startTouch == nil{
startTouch = touch?.location(in: drawingPlace)
storePoints.append(startTouch!)
}else{
for point in storePoints{
if location == point { // i want to say if location == point or near the point
startTouch = point // so the start touch equal the point
}
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
finalTouch = touch?.location(in: drawingPlace)
storePoints.append(finalTouch!)
if startTouch != nil{
UIGraphicsBeginImageContext(drawingPlace.frame.size)
drawingPlace.image?.draw(in: drawingPlace.bounds)
let context = UIGraphicsGetCurrentContext()
context?.beginPath()
context?.move(to: startTouch!)
context?.addLine(to: finalTouch!)
context?.strokePath()
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
drawingPlace.image = img
}
}
}
문제는 다음과 같습니다 :
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
let location = touch?.location(in: drawingPlace) //
if startTouch == nil{
startTouch = touch?.location(in: drawingPlace)
storePoints.append(startTouch!)
}else{
for point in storePoints{
if location == point { // i want to say if location == point or near the point
startTouch = point // so the start touch equal the point
}
}
}
}
내가 위치하면 원하는보기에서 사용자를 눌러 시작 터치는 배열에서 가까운 포인트가 될 때 touch는 storePoints 배열의 임의의 점 주위에 있으며, 그 다음 startTouch는 점과 같습니다.
나는 감사 할 것입니다.
마젠
어떤 문제가 있습니까? 너 충돌하고있어? 문제를 명확하게 설명하십시오. –
@RoboticCat 모든 것이 괜찮습니다.하지만 사용자가 시작 터치를 누르면 배열에서 가까운 지점이됩니다. – mazen
@RoboticCat touchesBegin 함수 설명을 확인하십시오. – mazen