Latest 1.0.3
Homepage https://github.com/King-Wizard/UITextField-Shake-Swift
License MIT
Platforms ios 8.4
Authors

UITextField-Shake-Swift CI Status

UITextField extension in Swift that adds shake animation

Initially created by Andrea Mazzini (using Objective-C) on 08/02/14: https://github.com/andreamazz/UITextField-Shake

Translated by myself from Objective-C to Swift and provided to you on this repository.

Setup with Cocoapods (recommended setup)

  • Add the instructions below to your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'UITextField-Shake-Swift'
  • Then add import UITextField_Shake_Swift at the top of your Swift class.

  • Finally compile and run and you will be good to go.

Otherwise you can also manually import the framework

Just drag and drop UITextFieldShakeSwift/UITextFieldShakeSwift/UITextField+Shake.swift file into your Xcode project and do not forget to check the checkbox entitled "Copy items if needed" and the appropriate checkboxe(s) in "Add to targets" section.

Usage

In Swift

// Shake
self.textField.shake()

// Shake with the default speed
self.textField.shake(10,              // 10 times
                     withDelta: 5.0   // 5 points wide
)

// Shake with a custom speed
self.textField.shake(10,              // 10 times
                     withDelta: 5.0,  // 5 points wide
                     speed: 0.03      // 30ms per shake
)

// Shake with a custom speed and direction
self.textField.shake(10,              // 10 times
                     withDelta: 5.0,  // 5 points wide
                     speed: 0.03,     // 30ms per shake
                     shakeDirection: ShakeDirection.Vertical
)

Completion Handler

You can also pass a closure that will be run as soon as the shake animation stops:

// Using the trailing closure syntax
self.textField.shake(10, withDelta: 5.0) {
    () -> Void in
    println("Called after TextField ended up shaking")
}

Latest podspec

{
    "name": "UITextField-Shake-Swift",
    "version": "1.0.3",
    "summary": "UITextField extension in Swift that adds shake animation",
    "description": "UITextField extension that adds a shake animation like the password field of the OsX login screen.",
    "homepage": "https://github.com/King-Wizard/UITextField-Shake-Swift",
    "license": "MIT",
    "authors": {
        "King-Wizard": "[email protected]"
    },
    "social_media_url": "https://twitter.com/KingWizardTwitt",
    "platforms": {
        "ios": "8.4"
    },
    "source": {
        "git": "https://github.com/King-Wizard/UITextField-Shake-Swift.git",
        "tag": "1.0.3"
    },
    "source_files": "UITextFieldShakeSwift/*.swift"
}

Pin It on Pinterest

Share This