我正在尝试在Xcode(Swift)中的图像上设置自定义手势。 手势是关于摩擦图像或连续挠痒,并在手指移动时以时间间隔触发我的功能。
我会在这里感谢一些帮助。
非常感谢。
答案 0 :(得分:-1)
//这是我的想法,未经过测试
var time = 0.0
var timeInterval = 1.0
var everyTime = 0.1
func addPan() {
let imageView = UIImageView()
//imageView.frame = xxxx
let pan = UIPanGestureRecognizer(target: self, action: #selector(panGesture(gesture:)))
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(pan)
}
func panGesture(gesture : UIPanGestureRecognizer) {
if gesture.state == .changed, time >= timeInterval {
print("time interval is \(everyTime) every is \(everyTime)")
}
}
func addtimer() {
let timer = Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
RunLoop.current.add(timer, forMode: RunLoopMode.commonModes)
}
func timerAction() {
time += timeInterval
if time >= timeInterval {
time = 0.0
}
}