我使用我的iOS應用潛望式註釋代碼(在評論氣泡從底部向上滑動):https://github.com/yoavlt/PeriscommentView的潛望式斯威夫特動漫評論
這是實際動畫的代碼評論:
public func addCell(cell: PeriscommentCell) {
cell.frame = CGRect(origin: CGPoint(x: 0, y: self.frame.height), size: cell.frame.size)
visibleCells.append(cell)
self.addSubview(cell)
UIView.animateWithDuration(self.config.appearDuration, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {() -> Void in
let dy = cell.frame.height + self.config.layout.cellSpace
for c in self.visibleCells {
let origin = c.transform
let transform = CGAffineTransformMakeTranslation(0, -dy)
c.transform = CGAffineTransformConcat(origin, transform)
}
}, completion: nil)
UIView.animateWithDuration(self.config.disappearDuration, delay: self.config.stayDuration, options: UIViewAnimationOptions.CurveEaseIn, animations: {() -> Void in
cell.alpha = 0.0
}) { (Bool) -> Void in
self.visibleCells.removeLast()
cell.removeFromSuperview()
}
}
上述代碼的問題是,有時當添加新評論時,它顯示重疊前面的評論。預期的行爲是先前的評論下滑,新評論取而代之。我注意到這主要發生在當前評論開始淡出之後添加新評論時,但仍然沒有消失。
我試着在self.visibleCells.removeLast()中放置一個斷點,它看起來好像只有當最後一個註釋完成時纔會被調用,所以我期望它能正常工作(因爲for循環向上移動所有可見的單元格,即使評論淡出,它仍然可見)。
任何幫助,這將不勝感激。
謝謝!
事實上,其他人報告相同的問題:https://github.com/yoavlt/PeriscommentView/issues/5 – Prabhu