Skip to content

Instantly share code, notes, and snippets.

@freele
Created December 13, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freele/6a3228fc672a514d05a51e4e66c95846 to your computer and use it in GitHub Desktop.
Save freele/6a3228fc672a514d05a51e4e66c95846 to your computer and use it in GitHub Desktop.
//
// SLRMenuButtonView.swift
// StreamLayer iOS
//
// Created by Alexander Kremenets on 12/12/2018.
// Copyright © 2018 StreamLayer, Inc. All rights reserved.
//
import Foundation
import UIKit
class SLRMenuButtonView: UIView {
init(tappableImage: SLRImageView) {
self.tappableImage = tappableImage
super.init(frame: tappableImage.frame)
loadSubviews()
initAnimators()
activateAnimations()
}
// MARK: Subviews
public var tappableImage: SLRImageView! = nil
private let tooltipButtonBackgroundEffect: UIView = {
let tooltipButtonBackgroundEffect = UIView()
tooltipButtonBackgroundEffect.backgroundColor = UIColor.red
tooltipButtonBackgroundEffect.borderColor = UIColor.white
tooltipButtonBackgroundEffect.clipsToBounds = true
tooltipButtonBackgroundEffect.layer.cornerRadius = 5
return tooltipButtonBackgroundEffect
}()
private var scaleChange1: UIViewPropertyAnimator! = nil
private var scaleChange2: UIViewPropertyAnimator! = nil
private func activateAnimations() {
self.scaleChange1.startAnimation()
// UIView.animate(withDuration: 1, delay: 0.25, options: UIView.AnimationOptions.curveEaseOut, animations: {
// self.tooltipButtonBackgroundEffect.backgroundColor = .orange
// self.tooltipButtonBackgroundEffect.transform = CGAffineTransform(scaleX: 1.25, y: 1.25)
//
// }, completion: nil)
}
private func initAnimators() {
self.scaleChange1 = UIViewPropertyAnimator(
duration: 1.5,
curve: .easeIn,
animations: { [weak self] in
self?.tooltipButtonBackgroundEffect.transform = CGAffineTransform(scaleX: 1.25, y: 1.25)
})
// scaleChange1.pausesOnCompletion = false
scaleChange1.addCompletion({_ in
self.scaleChange1.fractionComplete = 0.5
// self.scaleChange1.startAnimation()
})
}
private func loadSubviews() {
tooltipButtonBackgroundEffect.frame = self.bounds
self.addSubview(tooltipButtonBackgroundEffect)
self.addSubview(tappableImage)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment