当你开始关闭菜单时,当tableView被拉出屏幕或停止时,我无法弄清楚为什么tableViewcell的动画会发生frizzes。
为了让您更好地理解这个问题,这里有一个gif
我在自定义UITableViewCell类
上实现了Tap Gesture Recognizerlet tap = UITapGestureRecognizer(target: self, action: "tapAction")
self.addGestureRecognizer(tap)
func tapAction() {
let animationWidth = leftMenuWidth * 0.27
UIView.animateWithDuration(0.75, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .AllowUserInteraction, animations: {
self.colorIndicator.frame.size.width += animationWidth
}) { (true) in
UIView.animateWithDuration(0.75, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .AllowUserInteraction, animations: {
self.colorIndicator.frame.size.width -= animationWidth
}, completion: { (true) in
print("Animation Complete")
})
}
我也使用这个cocoaPods实现滑动菜单 - https://github.com/jonkykong/SideMenu
感谢。
答案 0 :(得分:0)
可能会重新加载单元格,导致动画重置。
尝试跟踪是否已点击某个单元格的状态,以便在重新加载时您可以将动画显示为已完成。您可以使用简单的字典来完成此操作。
在视图控制器的顶部,定义:
private var tapped = [Int : Bool]()
接下来,在cellForRowAtIndexPath:
中进行tableView检查:
if let isSet = tapped[view.hashValue] where isSet == true {
// display animation complete. You probably don't want to re-animate
// it if it's scrolled back into view, so just get it to the completed state.
}
最后,将您的点按操作从使用单元格中的手势切换到表格内的didSelectRowAtIndexPath:
:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// remember the cell has been tapped
tapped[view.hashValue] = true
// call your method to display the animation on the cell,
// something like cell.showAnimation(). It shouldn't animate if
// already displaying the completed animation state.
}
另外,我不建议在计算帧时使用+=
或-=
运算符,因为多次调用它会继续增长或缩小它。请改用显式值,例如= animationWidth
或= 0
。