UITextFieldShake
  • October 19, 2023

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

Screenshot


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”)
}

GitHub


View Github

#animation #awesemetextfield #carthage #cocoapods #currencytextfield #customtextfield #customwidgets #facetedsearch #geosearch #growingtextview #instantsearch #interfacebuilder #ios #ioslibrary #iosswift #objectivec #opensource #passwordtextfield #placeholder #placeholdertextview #realmswift #search #searchengine #searchinterface #searchsynonyms #styledtext #swift #swiftframework #swiftlibrary #swiftpackagemanager #swiftui #swiftuicomponents #text #textexpansion #textfield #texture #textview #tjtextfield #ui #uikit #uitextfield #uitextfieldnavigation #uitextview #uitextviewalgolia #widgets
YOU MIGHT ALSO LIKE...
PermissionsSwiftUI: A SwiftUI package to handle permissions

PermissionsSwiftUI displays and handles permissions in SwiftUI. It is largely inspired by SPPermissions. The UI is highly customizable and resembles an Apple style. ...

Pager tab strip view

Introduction PagerTabStripView is the first pager view built in pure SwiftUI. It provides a component to create interactive pager views ...

PageView

SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS.

Pages

    

How to take action when a property changes

1. Taking Action When a Property Changes: Property Observers Swift lets you observe and respond to changes in a property’s ...