Skip to content

Instantly share code, notes, and snippets.

View Aymenworks's full-sized avatar

Rebouh Aymen Aymenworks

View GitHub Profile
override func layoutSubviews() {
super.layoutSubviews()
foregroundButton.layer.cornerRadius = foregroundButton.bounds.height / 2.0
}
switch progress {
case AnimationState.full.rawValue...:
let newProgress = (progress - AnimationState.full.rawValue) / (AnimationState.finalBigSize.rawValue - AnimationState.full.rawValue)
let scale = 1 + (maxScale-1) * newProgress
foregroundButton.transform = CGAffineTransform(scaleX: scale, y: scale)
case ...AnimationState.full.rawValue:
foregroundButton.transform = .identity
default:
print("surprise")
func update(progress: CGFloat) {
let shiftedProgress = (progress - AnimationState.start.rawValue) / (AnimationState.full.rawValue - AnimationState.start.rawValue)
let height: CGFloat = foregroundButton.bounds.height * shiftedProgress
let rect = CGRect(x: 0, y: foregroundButton.bounds.height - height, width: foregroundButton.bounds.width, height: height)
let path = UIBezierPath(rect: rect).cgPath
shapeLayer.path = path
}
// ...
func setup() {
// ...
layout: do {
addSubview(backgroundButton)
class SearchView: UIView {
// MARK: Properties
// ...
struct Colors {
static let backgroundButtonBackgroundColor = UIColor.clear
static let backgroundButtonTintColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
static let foregroundButtonBackgroundColor = #colorLiteral(red: 1, green: 0.8, blue: 0, alpha: 1)
class SearchView: UIView {
// MARK: Properties
...
// MARK: Setup
func setup() {
class SearchView: UIView {
// MARK: Properties
...
struct Colors {
static let backgroundButtonBackgroundColor = UIColor.clear
static let backgroundButtonTintColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
static let foregroundButtonBackgroundColor = #colorLiteral(red: 1, green: 0.8, blue: 0, alpha: 1)
// We replace
let rect = CGRect(x: 0, y: 0, width: foregroundButton.bounds.width, height: height)
// by
let rect = CGRect(x: 0, y: foregroundButton.bounds.height - height, width: foregroundButton.bounds.width, height: height)
func update(progress: CGFloat) {
let height: CGFloat = foregroundButton.bounds.height * progress
let rect = CGRect(x: 0, y: 0, width: foregroundButton.bounds.width, height: height)
let path = UIBezierPath(rect: rect).cgPath
shapeLayer.path = path
}
class SearchView: UIView {
// MARK: Properties
enum AnimationState: CGFloat {
case start = 0.0, full = 0.7, finalBigSize = 1
}
}