Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: Playground - noun: a place where people can play
- import UIKit
- let shape = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
- shape.backgroundColor = .lightGray
- shape.layer.cornerRadius = shape.bounds.height/2
- let label = UILabel(frame: .zero)
- label.font = UIFont.boldSystemFont(ofSize: shape.bounds.height/2)
- var count = 1
- label.text = "\(count)"
- label.sizeToFit()
- let container = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 200))
- container.addSubview(shape)
- container.addSubview(label)
- container.backgroundColor = .white
- shape.center = container.center
- label.center = shape.center
- class Bla: NSObject {
- @objc func onTap(_ g: UIGestureRecognizer) {
- let duration: TimeInterval = 0.2
- let shrinkTo: CGFloat = 0.5
- UIView.animate(withDuration: duration, animations: {
- UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseIn], animations: {
- shape.transform.a = shrinkTo
- label.transform.d = 1 - 0.2 * shrinkTo
- })
- UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseOut], animations: {
- label.transform.a = 0.001
- label.transform.tx = -shape.bounds.width/2 * shrinkTo + 1
- }) { _ in
- count+=1
- label.text = "\(count)"
- label.sizeToFit()
- label.transform.tx = -label.transform.tx
- UIView.animate(withDuration: duration, animations: {
- UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseOut], animations: {
- shape.transform.a = 1
- label.transform.a = 1
- })
- UIView.animate(withDuration: 0, delay: 0, options: [.curveEaseIn], animations: {
- label.transform.d = 1
- label.transform.tx = 0
- })
- })
- }
- })
- }
- }
- let a = Bla()
- container.addGestureRecognizer(UITapGestureRecognizer(target: a, action: #selector(Bla.onTap(_:))))
- import PlaygroundSupport
- PlaygroundPage.current.liveView = container
- PlaygroundPage.current.needsIndefiniteExecution = true
Add Comment
Please, Sign In to add comment