在UIPanGestureRecognizer中的框架上的UIView.animate

时间:2017-12-28 19:33:22

标签: ios swift uiview uiviewanimation uipangesturerecognizer

我正在尝试构建一个UIPanGestureRecognizer委托,当UIView达到某个x值时会移动@objc func moveCardRec(sender: UIPanGestureRecognizer){ if sender.translation(in: self).x < -65.0 { self.makeButtonPop() } else { self.makeButtonUnPop() } } 的宽度/高度但是我遇到了这个奇怪的闪烁当值超过阈值时发生(在下面的示例中为65px)。

UIView

我认为,当我makeButtonPop()(我要弹出/动画的那一秒)时,我用摇动手势移动x值的观点正在移动一秒钟。落后或重置框架。毫无头绪。

附上现在正在发生的事情的GIF。你会看到它一瞬间就会紧张不安。 UIView.animate函数只是圆形图像视图框架上的var div = document.getElementById("aantallen"); var spans = div.querySelectorAll("span"); var totaalPersonen = 0; for(i=0;i<spans.length;i++) { const content = Number(spans[i].innerHTML) alert(content); totaalPersonen = Number(totaalPersonen) +content; alert(totaalPersonen); },其中带有复选标记。

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,我是个傻瓜。花了好几个小时。

找到了解决方法。确保要设置动画的UIView位于包含的UIView内(如父级)。所以上面的例子中,紫色圆圈在UIView范围内,不会改变大小。

父级中的孩子会更改大小。出于某些原因,当动画UIView和我拖动的那个在同一个容器/同一直接父母中时,他们彼此不喜欢并且闪烁。

希望这有助于其他人!