Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
keyboardWillShow: Optional([AnyHashable("UIKeyboardFrameBeginUserInfoKey"): NSRect: {{0, 1024}, {768, 313}}, AnyHashable("UIKeyboardFrameEndUserInfoKey"): NSRect: {{0, 711}, {768, 313}}, AnyHashable("UIKeyboardBoundsUserInfoKey"): NSRect: {{0, 0}, {768, 313}}, AnyHashable("UIKeyboardIsLocalUserInfoKey"): 1, AnyHashable("UIKeyboardCenterEndUserInfoKey"): NSPoint: {384, 867.5}, AnyHashable("UIKeyboardCenterBeginUserInfoKey"): NSPoint: {384, 1180.5}, AnyHashable("UIKeyboardAnimationCurveUserInfoKey"): 7, AnyHashable("UIKeyboardAnimationDurationUserInfoKey"): 0.25])
keyboardWillHide: Optional([AnyHashable("UIKeyboardFrameBeginUserInfoKey"): NSRect: {{0, 711}, {768, 313}}, AnyHashable("UIKeyboardFrameEndUserInfoKey"): NSRect: {{0, 1024}, {768, 313}}, AnyHashable("UIKeyboardBoundsUserInfoKey"): NSRect: {{0, 0}, {768, 313}}, AnyHashable("UIKeyboardIsLocalUserInfoKey"): 1, AnyHashable("UIKeyboardCenterEndUserInfoKey"): NSPoint: {384, 1180.5}, AnyHashable("UIKeyboardCenterBeginUserInfoKey"): NSPoint: {384, 867.5}, AnyHashable("UIKeyboardAnimationCurveUserInfoKey"): 7, AnyHashable("UIKeyboardAnimationDurationUserInfoKey"): 0.25])
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
// Define new Notification.Name
extension Notification.Name {
static let ButtonDidTap = Notification.Name(rawValue: "com.vialyx.ButtonDidTap")
import UIKit
final class ViewController: UIViewController {
@IBAction func photoLibraryDidTap(_ sender: Any) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Setup Fetch Interval
protocol HighlightAnimatable: class {
var settings: HighlightAnimatableSettings { get }
func lockAnimation()
func unlockAnimation()
func highlight(_ touched: Bool)
func highlight(_ touched: Bool, completion: ((Bool) -> Void)?)
}
struct HighlightAnimatableSettings {
var duration: TimeInterval = 0.5
var delay: TimeInterval = 0.0
var springDamping: CGFloat = 1.0
var springVelocity: CGFloat = 0.0
var options: UIView.AnimationOptions = [.allowUserInteraction]
var transform: CGAffineTransform = .init(scaleX: 0.90, y: 0.90)
}
private struct AssociatedKeys {
static var highlightAnimation = "VIV_highlightAnimation"
}
extension HighlightAnimatable where Self: UIView {
private var animationAvailable: Bool {
get { return (objc_getAssociatedObject(self, &AssociatedKeys.highlightAnimation) as? Bool) ?? true }
set { objc_setAssociatedObject(self, &AssociatedKeys.highlightAnimation, newValue, .OBJC_ASSOCIATION_ASSIGN) }
}
import UIKit
class AnimatableButton: UIButton, HighlightAnimatable {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
highlight(true)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
import UIKit
class AnimatableTableViewCell: UITableViewCell, HighlightAnimatable {
var settings: HighlightAnimatableSettings {
var settings = HighlightAnimatableSettings()
settings.transform = .init(scaleX: 0.70, y: 0.70)
settings.duration = 0.3
return settings
}