Created
April 2, 2014 03:25
-
-
Save davidolesch/9927462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DOViewController.m | |
// LoginForm | |
// | |
// Created by David Olesch on 4/1/14. | |
// Copyright (c) 2014 David Olesch. All rights reserved. | |
// | |
#import "DOViewController.h" | |
@interface DOViewController () | |
@property (strong, nonatomic) IBOutlet UITextField *usernameField; | |
@property (strong, nonatomic) IBOutlet UITextField *passwordField; | |
@property (strong, nonatomic) IBOutlet UIButton *loginButton; | |
@property (strong, nonatomic) UIDynamicAnimator *animator; | |
@end | |
@implementation DOViewController | |
- (IBAction)loginButtonTouched:(id)sender { | |
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; | |
NSArray *formElements = @[self.usernameField,self.passwordField,self.loginButton]; | |
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:formElements]; | |
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES; | |
[self.animator addBehavior:collisionBehavior]; | |
UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:formElements]; | |
gravityBehavior.gravityDirection = CGVectorMake(0, 1); | |
[self.animator addBehavior:gravityBehavior]; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:self.usernameField snapToPoint:CGPointMake(140, 100)]; | |
snapBehavior.damping = 1.f; | |
[self.animator addBehavior:snapBehavior]; | |
[self.animator removeBehavior:gravityBehavior]; | |
UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:formElements]; | |
gravityBehavior.gravityDirection = CGVectorMake(0, -1); | |
[self.animator addBehavior:gravityBehavior]; | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment