Tôi có một chế độ xem có chức năng panGesture, nhưng tôi cần phải gửi cử chỉ xoay từ điểm này sang điểm khác theo chương trình. Có cách nào để làm điều này nhanh chóng bằng cách sử dụng một hình ảnh động với một khoảng thời gian cụ thể? Đây là nỗ lực của tôi lúc gọi cử chỉ chảo cách lập trình:Làm thế nào để lập trình gửi một pangesture trong swift
var upPanPoint = CGPoint(x: contentView.center.x, y: contentView.center.y + 500)
var upPan = panGestureRecognizer.setTranslation(upPanPoint, inView: self)
onSwipe(upPan)
đây là mã mà công nhận cử chỉ chảo:
func onSwipe(panGestureRecognizer : UIPanGestureRecognizer!) {
let view = panGestureRecognizer.view!
print(view)
switch (panGestureRecognizer.state) {
case UIGestureRecognizerState.Began:
if (panGestureRecognizer.locationInView(view).y < view.center.y) {
self.viewState.rotationDirection = .RotationAwayFromCenter
} else {
self.viewState.rotationDirection = .RotationTowardsCenter
}
case UIGestureRecognizerState.Ended:
self.finalizePosition()
default:
let translation : CGPoint = panGestureRecognizer.translationInView(view)
view.center = self.viewState.originalCenter + translation
self.rotateForTranslation(translation, withRotationDirection: self.viewState.rotationDirection)
self.executeOnPanForTranslation(translation)
}
}
Cảm ơn trước!
Có thể thử gọi một số phương thức chạm của 'NSView' theo thứ tự thích hợp. – k06a
Có lẽ bạn phải đặt 'upPan.state' thành' .Changed' (hoặc một số giá trị khác với '.Possible', cho phép bạn nhận ra nó). –
bản sao có thể có của [UITapGestureRecognizer Lập trình kích hoạt một lần nhấn trong chế độ xem của tôi] (http://stackoverflow.com/questions/14094691/uitapgesturerecognizer-programmatically-trigger-a-tap-in-my-view) – s1ddok