一旦手势结束,实例变量将重置为零

时间:2015-10-01 04:03:58

标签: ios swift

@IBAction func OnRightSwipeGesture(sender: UIPanGestureRecognizer) {
    let translated = sender.translationInView(self.view);

    let diffTrans = (translated.y - previouslyTranslated.y) / 75;
    sum += diffTrans;
    print(sum);
    colorWheel.transform = CGAffineTransformMakeRotation(sum);
    previouslyTranslated = translated;
}

在这个函数中,我每次调用后都会添加翻译的差异。然后,当我把手指从设备上移开并尝试制作新手势时,总和被重置为0.总和被声明在课程顶部,我非常困惑......

1 个答案:

答案 0 :(得分:0)

你应该检查一下手势识别器的state,并且只在等于UIGestureRecognizerStateChanged时更新你的变量。