Created
March 12, 2014 09:22
-
-
Save cowdinosaur/9503554 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
// | |
// YACViewController.m | |
// YetAnotherClone | |
// | |
// Created by Akmal Abdul Rahman on 12/3/14. | |
// Copyright (c) 2014 Akmal Abdul Rahman. All rights reserved. | |
// | |
#import "YACViewController.h" | |
@interface YACViewController () | |
@property (strong, nonatomic) UIView *balloon; | |
@property (strong, nonatomic) UIView *ground; | |
@property (strong, nonatomic) NSMutableArray *scenery; | |
@property (strong, nonatomic) UIDynamicAnimator *animator; | |
@property (strong, nonatomic) UIPushBehavior *floatUp; | |
@end | |
@implementation YACViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
UIImage *bgImage = [UIImage imageNamed:@"Background.png"]; | |
UIImageView *bgView = [[UIImageView alloc] initWithImage:bgImage]; | |
bgView.layer.magnificationFilter = kCAFilterNearest; | |
bgView.frame = CGRectMake(0, self.view.bounds.size.height - 570, 320, 570); | |
[self.view addSubview:bgView]; | |
self.balloon = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 50)]; | |
UIImage *balloonImage = [UIImage imageNamed:@"Balloon.png"]; | |
UIImageView *balloonView = [[UIImageView alloc] initWithImage:balloonImage]; | |
balloonView.layer.magnificationFilter = kCAFilterNearest; | |
balloonView.frame = CGRectMake(-5, -5, 50, 140); | |
[self.balloon addSubview:balloonView]; | |
self.balloon.center = CGPointMake(50, self.view.bounds.size.height/2); | |
[self.view addSubview:self.balloon]; | |
self.animator = [[UIDynamicAnimator alloc] init]; | |
// add Gravity behaviour to balloon | |
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.balloon]]; | |
gravity.magnitude = 0.1; | |
[self.animator addBehavior:gravity]; | |
// add floating behaviour | |
self.floatUp = [[UIPushBehavior alloc] initWithItems:@[self.balloon] mode:UIPushBehaviorModeInstantaneous]; | |
self.floatUp.pushDirection = CGVectorMake(0, -1); | |
self.floatUp.active = NO; | |
[self.animator addBehavior:self.floatUp]; | |
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)]; | |
[self.view addGestureRecognizer:tapGestureRecognizer]; | |
} | |
- (void)tapped | |
{ | |
self.floatUp.active = YES; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment