2017-04-06 00:55:41 +08:00
|
|
|
//
|
2019-01-20 12:34:40 +01:00
|
|
|
// UITextFieldExtension.swift
|
2021-08-28 07:32:31 +02:00
|
|
|
// passKit
|
2017-04-06 00:55:41 +08:00
|
|
|
//
|
|
|
|
|
// Created by Yishi Lin on 5/4/17.
|
|
|
|
|
// Copyright © 2017 Yishi Lin. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
private var kAssociationKeyNextField: UInt8 = 0
|
|
|
|
|
|
|
|
|
|
extension UITextField {
|
|
|
|
|
@IBOutlet var nextField: UITextField? {
|
|
|
|
|
get {
|
2020-06-28 21:25:40 +02:00
|
|
|
objc_getAssociatedObject(self, &kAssociationKeyNextField) as? UITextField
|
2017-04-06 00:55:41 +08:00
|
|
|
}
|
|
|
|
|
set(newField) {
|
|
|
|
|
objc_setAssociatedObject(self, &kAssociationKeyNextField, newField, .OBJC_ASSOCIATION_RETAIN)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-28 21:25:40 +02:00
|
|
|
|
2019-09-29 00:28:46 +08:00
|
|
|
func shake() {
|
|
|
|
|
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
|
|
|
|
|
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
|
|
|
|
|
animation.repeatCount = 3
|
2020-06-28 21:25:40 +02:00
|
|
|
animation.duration = 0.2 / TimeInterval(animation.repeatCount)
|
2019-09-29 00:28:46 +08:00
|
|
|
animation.autoreverses = true
|
|
|
|
|
animation.values = [3, -3]
|
|
|
|
|
layer.add(animation, forKey: "shake")
|
|
|
|
|
}
|
2017-04-06 00:55:41 +08:00
|
|
|
}
|