사용자가 TableViewCell을 터치 한 다음 새로 만든 UIView를 다른 부분으로 드래그하여 새 UIView를 만들 수있는 기능을 만들려고합니다. 화면을 드롭 할 수 있습니다. 문제는 두 가지 동작으로이 작업을 수행 할 수 있다는 것입니다.하지만 내 인생에서 한 번의 제스처로 수행하는 방법을 파악할 수 없습니다.Swift (iOS) 하나의 제스처로 항목을 만들고 끌어옵니다 (터치 이벤트 전달)
나는 광범위한 독서를했으며 몇 가지 유망한 답변을 찾았지만 그 중 누구도 나를 위해 일하는 것 같지 않습니다.
Tutorial on How to drag and drop item from UITableView to UITableView
Manually passing touches Began to a newly created instance
난에 계속 실행되는 특정 문제이며, 그 생성 및 드래그 기능이 있지만 즉시 셀을 떠날 때, 손가락이 TableViewCell 위에있을 때 작동하는 것 같다, 끌기가 멈추고 사용자는 항목을 다시 잡아야합니다.이 시점에서 모든 것이 올바르게 작동합니다.
각 TableViewCell는 다음 코드 touchesBegan 함수 재정의된다 ('대리자'메인 뷰 컨트롤러)
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
// Store the touch location
let touch = touches.anyObject()! as UITouch
delegate?.touchLocation = touch.locationInView(self.superview!.superview!.superview!)
// Add a new draggable UIView to the main view
delegate?.addNewDraggableItem(self)
}
메인 뷰 컨트롤러는 그러나 hitTest 함수를 겹쳐 맞춤 UIView 하위 가지고
을override func hitTest (point: CGPoint, withEvent event: UIEvent?) -> UIView {
var rv: UIView? = nil
for child in self.subviews as [UIView] {
if(child.isKindOfClass(DraggableView)) {
rv = child;
child.center = point;
break;
}
}
if(rv == nil){
rv = super.hitTest(point, withEvent:event)
}
return rv!
}
내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까?
이 질문에 대한 답변을 찾으셨습니까? – user4812000