Skip to content

Instantly share code, notes, and snippets.

@mehmetfarhan
Created May 9, 2019 13:14
Show Gist options
  • Save mehmetfarhan/c9a545e554ba11bd5b45630c0c4edc60 to your computer and use it in GitHub Desktop.
Save mehmetfarhan/c9a545e554ba11bd5b45630c0c4edc60 to your computer and use it in GitHub Desktop.
Flay Shopping Cart
private var badge = BadgeBarButtonItem()
var counterItem = 0
@objc
func didTappedAddToCart(with imageView: UIImageView?) {
guard let imageView = imageView else { return }
let bounds = imageView.bounds
let size = imageView.frame.size
let imageViewPosition = imageView.convert(bounds.origin, to: self.view)
let imgViewTemp = UIImageView(
frame: CGRect(
x: imageViewPosition.x,
y: imageViewPosition.y,
width: size.width,
height: size.height)
)
imgViewTemp.image = imageView.image
imgViewTemp.layer.cornerRadius = imageView.layer.cornerRadius
imgViewTemp.clipsToBounds = imageView.clipsToBounds
imgViewTemp.contentMode = imageView.contentMode
animation(tempView: imgViewTemp)
}
func animation(tempView: UIView) {
self.view.addSubview(tempView)
UIView.animate(withDuration: 1.0,
animations: {
tempView.animationZoom(scaleX: 1.5, scaleY: 1.5)
}, completion: { _ in
UIView.animate(withDuration: 0.5, animations: {
tempView.animationZoom(scaleX: 0.2, scaleY: 0.2)
tempView.animationRoted(angle: CGFloat(Double.pi))
tempView.frame.origin.x = self.view.frame.maxX - 50
tempView.frame.origin.y = -10
}, completion: { _ in
tempView.removeFromSuperview()
UIView.animate(withDuration: 1.0, animations: {
self.counterItem += 1
self.badge.badgeText = "\(self.counterItem)"
self.badge.badgeButton?.animationZoom(scaleX: 1.2, scaleY: 1.2)
}, completion: {_ in
self.badge.badgeButton?.animationZoom(scaleX: 1.0, scaleY: 1.0)
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment