0
我有一個Instagram贊飼料 飼料有很多職位。每篇文章都有類似按鈕。如何在swift 3中每次在我的Feed中喜歡某個帖子時執行動畫?
每當用戶點擊喜歡 MyUiView
let likeImageView: UIButton = {
let button = UIButton(type: .custom)
button.setImage(#imageLiteral(resourceName: "like_unselected"), for: .normal)
let tap = UITapGestureRecognizer(target: self, action: #selector(loveButtonTapped))
tap.numberOfTapsRequired = 1
button.addGestureRecognizer(tap)
return button
}()
我正在和傳遞用戶水龍頭的位置通過delegate.I用這種方法得到正確的所需的位置。
@objc func loveButtonTapped(sender: UITapGestureRecognizer){
guard var location : CGPoint = sender.view?.superview?.frame.origin else { return }
var loc = convert(location, to: nil)
self.delegate?.onloveButtonTapped(loc: loc, for: self)
}
現在我FeedController(這是UIcollectionViewController)
func likeButtonTapped(loc: CGPoint, for cell: PostUi){
print("like button tapped")
var touchLocation: CGPoint = loc
print(touchLocation)
...
... //like implementation and checks
...
var i = Int(location.x)
var j = Int(location.y)
let path = UIBezierPath()
path.move(to: CGPoint(x:i, y:j))
//more code for animation
}
現在,當我點擊像按鈕,從第一篇文章我的動畫作品,但是當我向下滾動另一個帖子並點擊按鈕,動畫仍然有效,但無法看到,因爲它發生在頂端。每改變一次按鈕,我都會改變座標,但CGPoint起始點的路徑從進給起點開始計算。我應該做什麼使它正常工作?