UITextField category that adds shake animation

Overview

Build Status CocoaPods Cocoapods Coverage Status Carthage compatible

UITextField category that adds a shake animation like the password field of the OsX login screen.

Screenshot

UITextField+Shake

Setup with CocoaPods

pod 'UITextField+Shake', '~> 1.2'

Import UITextField+Shake.h in your controller's header file, or UITextField_Shake if you are using the use_frameworks! directive.

Setup with Carthage

github "andreamazz/UITextField-Shake"

Usage

In Objective-C

// Shake
[[self.textField] shake];

// Shake with the default speed
[self.textField shake:10   // 10 times
            withDelta:5    // 5 points wide
];

// Shake with a custom speed
[self.textField shake:10   // 10 times
            withDelta:5    // 5 points wide
                speed:0.03 // 30ms per shake
];

// Shake with a custom speed and direction
[self.textField shake:10   // 10 times
            withDelta:5    // 5 points wide
                speed:0.03 // 30ms per shake
       shakeDirection:ShakeDirectionVertical
];

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 completion block that will be performed as soon as the shake animation stops

- (void)shake:(int)times withDelta:(CGFloat)delta completion:(void((^)()))handler;
- (void)shake:(int)times withDelta:(CGFloat)delta speed:(NSTimeInterval)interval completion:(void((^)()))handler;
- (void)shake:(int)times withDelta:(CGFloat)delta speed:(NSTimeInterval)interval shakeDirection:(ShakeDirection)shakeDirection completion:(void((^)()))handler;

or in Swift using the trailing closure syntax:

textField.shake(10, withDelta: 5) {
    println("done")
}

Author

Andrea Mazzini. I'm available for freelance work, feel free to contact me.

Want to support the development of these free libraries? Buy me a coffee ☕️ via Paypal.

Contributors

Thanks to everyone kind enough to submit a pull request.

MIT License

Copyright (c) 2017 Andrea Mazzini. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Comments
  • Position Independent Executable

    Position Independent Executable

    First, thank you for this great work, it's extremely handy.

    I am having warnings when uploading my app to the store after adding this framework from Cocoa Pods. They say the app is no longer a PIE and after reading here it seems it can be caused by other libraries.

    This is the only pod on this project so I'm almost certain it is the cause. I have tried the suggestions from the link above and while the command line tool shows the app has the PIE flag I continue to receive app store warnings. So it may also be an App store issue.

    Has anyone else reported this? I will continue searching on my end

    opened by Juice805 8
  • UIView category

    UIView category

    Not really an issue, but is there a reason this isn't implemented directly on UIView? I think some other subclasses (like UITableViewCell for example) could benefit from it.

    opened by guillaumealgis 4
  • Problem with CocoaPod Update

    Problem with CocoaPod Update

    I attempted to perform a cocoapod update in a current project and got an error. I am enough of a newbie at cocoapods that I have no clue what it means or what needs to be done to fix it. Can you help?

    Update all pods Analyzing dependencies Downloading dependencies ... [Installing other Pods]... Installing UITextField+Shake (0.2) [!] Pod::Executable remote update

    error: cannot open FETCH_HEAD: Permission denied

    question 
    opened by rlaurb 2
  • Warning - This block declaration is not a prototype

    Warning - This block declaration is not a prototype

    I am getting this warning "This block declaration is not a prototype", I am using Swift 4 with Xcode 9.2 (9C40b).

    This warning I am getting in

    UITextField+Shake.m

    on line number 41

    opened by anirudhamahale 1
  • Shake correct number of times, instead of 1/2 as much

    Shake correct number of times, instead of 1/2 as much

    This could be intended behavior, but by decrementing "times" and incrementing "currentTimes" with each function call, the UITextField will only complete 1/2 as many full shakes as desired.

    By "shake", did you mean "one direction" or "a full transform in both directions"?

    If this change isn't wanted, perhaps adding some documentation about what constitutes a shake would be nice?

    Great class extension, by the way!

    opened by ethansinjin 1
  • Functions containing blocks are not available in Swift.

    Functions containing blocks are not available in Swift.

    These three methods available below are not displayed by the auto-completion when using Swift:

    - (void)shake:(int)times withDelta:(CGFloat)delta completion:(void((^)()))handler;
    - (void)shake:(int)times withDelta:(CGFloat)delta speed:(NSTimeInterval)interval completion:(void((^)()))handler;
    - (void)shake:(int)times withDelta:(CGFloat)delta speed:(NSTimeInterval)interval shakeDirection:(ShakeDirection)shakeDirection completion:(void((^)()))handler;
    

    Nonetheless the others which do not use blocks are usable and displayed by the auto-completion tool in the last version of Xcode. I tried to call them manually in a Swift project (the three methods above) but I was not successful.

    So to by-pass this problem I had to call these functions from an Objective-C class which itself was called by a Swift class.

    So you should fix this problem by rewriting this API in Swift.

    Thank you in advance.

    Best regards.

    opened by King-Wizard 1
  • Correct to use 'shakeDirection'

    Correct to use 'shakeDirection'

    - (void)shake:(int)times withDelta:(CGFloat)delta andSpeed:(NSTimeInterval)interval shakeDirection:(ShakeDirection)shakeDirection
    {
        [self shake:times withDelta:delta andSpeed:interval shakeDirection: shakeDirection completion:nil];
    }
    
    opened by mane-sandeep 1
  • Fix the reset to CGAffineTransformIdentity not being animated

    Fix the reset to CGAffineTransformIdentity not being animated

    When reseting the text field to its original position with CGAffineTransformIdentity, the change is not animated, which makes the text field "jump" at the end of the animation.

    Before fix: https://dl.dropboxusercontent.com/u/18386288/UIView%2BShake_before.mov After fix: https://dl.dropboxusercontent.com/u/18386288/UIView%2BShake_after.mov

    (sorry, .mov videos, could not find a satisfying gif converter...)

    Also, please note that the first and last animations are executed with the same duration as all the others shakes, but the distance travelled by the view is 2x smaller, making these appear "slower".

    Issue mirrored for UIView+Shake here: https://github.com/andreamazz/UIView-Shake/pull/1

    opened by guillaumealgis 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
Releases(1.1.2)
Owner
Andrea Mazzini
💻 Software Engineer 🌲 Woodworker
Andrea Mazzini
An UITextField subclass to simplify country code's picking. Swift 5.0

Preview Installation NKVPhonePicker is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'NKVPhonePicker'

Nike Kov 140 Nov 23, 2022
HTYTextField A UITextField with bouncy placeholder.

HTYTextField - A UITextField with bouncy placeholder. Screenshot Installation CocoaPods Add the dependency to your Podfile

Hanton Yang 312 Nov 13, 2022
Fully-wrapped UITextField made to work entirely in SwiftUI

iTextField ⌨️ A fully-wrapped `UITextField` that works entirely in SwiftUI. ?? Get Started | Examples | Customize | Install | Get Started Install iTex

Benjamin Sage 89 Jan 2, 2023
UITextField character counter with lovable UX 💖. No math skills required 🙃.

TextFieldCounter UITextField character counter with lovable UX ??. No math skills required ??. Features Set max length of UITextField. A beautiful an

Fabricio Serralvo 434 Dec 22, 2022
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews

' __________________ _______ _________ _______ _________ _______ _ ______ ' |\ /|\__ __/\__ __/( ____ \|\ /

Thanh Pham 446 Nov 24, 2022
Animated UITextField enhance UX for the user by giving clarity that they are focused

JDCircularProgress JDTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from the rest

Jawad Ali 22 Nov 17, 2022
Animated Subclass of UITextField created with CABasicAnimation and CAShapeLayer

JDAnimatedTextField JDAnimatedTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from

Jawad Ali 25 Dec 13, 2022
This project will add a done button on your UITextField and UITextView

This project will add a done button on your UITextField and UITextView

Botla Venkatesh 0 Nov 23, 2021
UITextField subclass with floating labels

JVFloatLabeledTextField JVFloatLabeledTextField is the first implementation of a UX pattern that has come to be known the "Float Label Pattern". Due t

Jared Verdi 7.2k Jan 2, 2023
iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more apps having maps.

MVAutocompletePlaceSearchTextField iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more app

Mrugrajsinh Vansadia 68 May 27, 2022
Subclass of UITextField that shows inline suggestions while typing.

AutocompleteField Subclass of UITextField that shows inline suggestions while typing. Plug and play replacement for UITextField. Delimiter support. Pe

Filip Stefansson 663 Dec 6, 2022
UITextfield subclass with autocomplete menu. For iOS.

MLPAutoCompleteTextField "We believe that every tap a user makes drains a tiny bit of their energy and patience. Typing is one of the biggest expendit

Eddy Borja 1.2k Nov 11, 2022
UITextField with underline and left image

TJTextField UITextField with underline and left image Version: 1.0 Features Add image in UITextField Left text pedding Underline whole UITextField Sho

Tejas Ardeshna 44 May 16, 2022
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.

Deprecated Please use JVFloatLabeledTextField instead or feel free to chime in on an issue if you'd like to take over the repo. RPFloatingPlaceholders

rob phillips 1.1k Jan 5, 2023
UITextField that automatically formats text to display in the currency format

CurrencyTextField The numbers that the user enters in the field are automatically formatted to display in the dollar amount format. For example, if th

Richa Deshmukh 49 Sep 28, 2022
UITextField that support currency in the right way.

PLCurrencyTextField Summary PLCurrencyTextField provides simple and user friendly support for the amount in the currency. Usage To start using the com

Łukasz Śliwiński 96 Nov 14, 2022
Animated UITextField and UITextView replacement for iOS

AnimatedTextInput iOS custom text input component used in the Jobandtalent app. Installation Use cocoapods to install this custom control in your proj

jobandtalent 757 Dec 15, 2022
UITextField subclass with autocompletion suggestions list

SearchTextField Overview SearchTextField is a subclass of UITextField, written in Swift that makes really easy the ability to show an autocomplete sug

Alejandro Pasccon 1.1k Dec 28, 2022
UITextField-based control for (NS)Measurement values input.

MeasurementTextField UITextField-based control for (NS)Measurement values input. Provides type-safe keyboard and picker based input of different measu

Siarhei Fiedartsou 16 Jul 22, 2021