UIView category that adds shake animation

Overview

Build Status CocoaPods codecov Carthage compatible

UIView category that adds a shake animation like the password field of the OSX login screen.

Screenshot

UIView+Shake

Setup with CocoaPods

  • Add pod 'UIView+Shake' to your Podfile
  • Run pod install
  • Run open App.xcworkspace

Objective-C

Import UIView+Shake.h in your controller's header file

Swift

If you are using use_frameworks! in your Podfile, use this import:

import UIView_Shake

Usage

In Objective-C

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

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

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

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

In Swift

// Shake
self.view.shake()

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

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

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

Direction

The shake direction is either .Vertical, .Horizontal or .Rotation

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:

view.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) 2015 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
  • @import prevent using the pod in project not supporting modules

    @import prevent using the pod in project not supporting modules

    Using the @import syntax prevent the pod to build if included in project disabling modules.

    See this StackOverflow question for the same issue in the GoogleAnalytics pod.

    Using the @import syntax does not provides much, as #import will still use modules as long as the project opted-in to use them:

    You don't actually need to use the @import keyword. If you opt-in to using modules, all #import and #include directives are mapped to use @import automatically.

    https://stackoverflow.com/questions/18947516/import-vs-import-ios-7

    opened by guillaumealgis 4
  • Shake in completion block of another shake

    Shake in completion block of another shake

    Is it even possible? I tried this and it works, but shake inside the completion handler looks like it has smaller delta than given. It barely shakes vertical.

    view.subviews.forEach {
        $0.shake(5, withDelta: 50.0, speed: 1.0, shakeDirection: .Horizontal, completion: { 
            self.view.subviews.forEach {
                $0.shake(5, withDelta: 50.0, speed: 1.0, shakeDirection: .Vertical, completion: nil)
            }
        })
    }
    
    question 
    opened by sochalewski 2
  • Enabled bit code for both build and archive

    Enabled bit code for both build and archive

    Enabled bit code for both build and archive. As a side effect this makes the library support bit code enabled projects that use Carthage

    For reference follow https://github.com/Carthage/Carthage/issues/535

    if BITCODE_GENERATION_MODE is not set to bitcode, projects using carthage will not be able to submit apps to appstore (or just archive them) even when enable bitcode setting is set to yes. Explanation in the link above.

    The library is used in www.monogram.me

    opened by gabrielnica 2
  • Fix crash resulting from failure to guard against nil completion handler

    Fix crash resulting from failure to guard against nil completion handler

    The addition of an unguarded completion handler in the 0.4 release results in a crash (EXC_BAD_ACCESS) when the completion handler is nil (i.e. the default when not using the new method).

    This PR adds a nil check to guard against this.

    opened by jnic 2
  • Fix the reset to CGAffineTransformIdentity not being animated

    Fix the reset to CGAffineTransformIdentity not being animated

    When reseting the view to its original position with CGAffineTransformIdentity, the change is not animated, which makes the view "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 UITextField+Shake here: https://github.com/andreamazz/UITextField-Shake/pull/5

    opened by guillaumealgis 2
  • Replace `direction` with `shakeDirection` in documentation comments

    Replace `direction` with `shakeDirection` in documentation comments

    The documentation comments were out of sync with the actual name of the arguments for two methods, raising a warning with the -Wdocumentation compiler flag.

    opened by guillaumealgis 1
  • import UIKit in header file

    import UIKit in header file

    You should always add UIKit to your header files if needed. So no UIKit or predefinition is needed when using UIView+Shake.h

    (plus: AppCode adds the automatic imported header files always to the top row so another manual step is needed or it will not compile)

    opened by ldrr 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.4)
Owner
Andrea Mazzini
💻 Software Engineer 🌲 Woodworker
Andrea Mazzini
Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation Sica can execute various animations sequentially or parallelly. Features Animation with duration and delay parallel /

CATS Open Source Softwares 1k Nov 10, 2022
An experiment for using SwiftUI's custom timing Animation to create an orbital-like animation.

Orbital-SwiftUI-Animation An experiment for using SwiftUI's custom timing curve to create an orbital-like animation. How it looks: How it works: Apply

Mostafa Abdellateef 7 Jan 2, 2023
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.

AnimatedCollectionViewLayout Normally a UICollectionView has no transition effects when you scroll from one item to another. There are lots of ways to

Jin Wang 4.5k Jan 1, 2023
Shimmer: A super-light modifier that adds a shimmering effect to any SwiftUI View

SwiftUI-Shimmer ✨ Shimmer is a super-light modifier that adds a shimmering effec

Vikram Kriplaney 389 Jan 2, 2023
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
DaisyChain is a micro framework which makes UIView animations chaining dead simple.

DaisyChain DaisyChain is a micro framework which makes UIView animations chaining dead simple. It uses the exact same interface you are familiars with

Ali Karagoz 31 Nov 3, 2022
UIView subclass that bends its edges when its position changes.

AHKBendableView BendableView is a UIView subclass that bends its edges when its position change is animated. Internally, BendableView contains CAShape

Arek Holko 591 Jul 24, 2022
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
DynamicBlurView is a dynamic and high performance UIView subclass for Blur.

DynamicBlurView DynamicBlurView is a dynamic and high performance UIView subclass for Blur. Appetize's Demo Since using the CADisplayLink, it is a hig

Kyohei Ito 929 Jan 5, 2023
Chain multiple UIView animations without endlessly nesting in completion closures.

⛓ Chain multiple UIView animations without endlessly nesting in completion closures. Used in some of the more superfluous animations in the OK Video app.

Pim 78 Dec 26, 2022
ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation

ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation. Demo Requirements iOS 9.0+ Xcode 8 Insta

Yansong Li 775 Dec 7, 2022
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Draven 1.9k Dec 9, 2022
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

Kazumasa Shimomura 127 Dec 14, 2022
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Shohei Yokoyama 3k Dec 27, 2022
Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

IBAnimatable 8.6k Jan 2, 2023
A Fast Animation Engine with an Intuitive API

Kinieta An Animation Engine for iOS with an Intuitive API and Readable Code! (Written in Swift 4.0.) Why another? I decided to build an Animation Engi

Michael Michailidis 44 Sep 22, 2022