我正在尝试以编程方式在UIPanGestureRecognizer
中设置UIView
的译文以进行单元测试,但是,它似乎无法识别译文。
这是我设置翻译的代码:
let gestureRecognizer = UIPanGestureRecognizer()
gestureRecognizer.state = .began
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
view.addGestureRecognizer(gestureRecognizer)
let translation = CGPoint(x: 10, y: 10)
gestureRecognizer.setTranslation(translation, in: view)
然后,我将手势识别器和视图都传递给使用此代码行的函数:
let translation = gestureRecognizer.translation(in: view)
它始终显示为(0.0, 0.0)
,而不是(10.0, 10.0)
。为什么?!