Powered by
Powered by
HuntMyIdeas-Inspire You To Make It Happen
Follow
   Me
  • Blogs
  • About Me
  • Home

How to create a Coin Fall Animation

6/22/2014

1 Comment

 
Picture
Animations provide best visual transitions between your user interface.

​In iOS,animations are used extensively to relocate views, change their size, remove them from view hierarchies, and hide them.

You might use animations to convey feedback to the user or to implement interesting visual effects.

In iOS, creating sophisticated animations does not require you to write any drawing code. .

This is how a sprite can be animated to show a coin fall. 
I am going to share source code  how to display  coin drop animation.

You can implement these codes to represent your App with cool effects.
Create Project:

Create a new project in Xcode: File\New\New Project. Pick the Single View Application template and call it CoinDropAnimation.

Don't forget to check ARC and Storyboard. Even if in this tutorial we won’t be focusing on these new technologies, it is a good way to come across the new ideas.

​Sprite.h

​#import <UIKit/UIKit.h>
@interface Sprite : UIImageView
{
NSUInteger uiValue;
NSInteger iValue;
CGFloat fValue;
}
@property (nonatomic, assign) NSUInteger uiValue;
@property (nonatomic, assign) NSInteger iValue;
@property (nonatomic, assign) CGFloat fValue;
@end

Sprite.m


#import "Sprite.h"
@implementation Sprite

@synthesize iValue, uiValue, fValue;
- (id)initWithImage:(UIImage *)image {
if ((self = [super initWithImage:image])) {
 // Initialization code
 }
    return self;
}
@end



SpriteHelpers.h

#import <Foundation/Foundation.h>
#import "Sprite.h"
@interface SpriteHelpers : NSObject {
}
+ (Sprite *)setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)filePrefix withDuration:(CGFloat)duration ofType:(NSString *)ext withValue:(NSInteger)val;
@end

​

SpriteHelpers.m

 #import "SpriteHelpers.h"

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )


@implementation SpriteHelpers

+ (Sprite *)setupAnimatedSprite:(id)sender numFrames:(NSInteger)frames withFilePrefix:(NSString *)filePrefix withDuration:(CGFloat)duration ofType:(NSString *)ext withValue:(NSInteger)val {
// Create an array for for holding the frames of the animation
NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:8];
// Just like above but instead loop back down and add the images in reverse except drop the first and last frames
for(int i =frames; i > 1; i--){
UIImage *sprite = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.%@",filePrefix,i,ext]];
[spriteArray addObject:sprite];
}

int k=arc4random()%6;
// Create a new Sprite and init with the first image of our spriteArray (doesn't matter what image)
Sprite *spriteViewTemp = [[Sprite alloc] initWithImage:[spriteArray objectAtIndex:k]];
// This nullifies what image we added above and instead sets up an animated Sprite with the contents of our spriteArray
[spriteViewTemp setAnimationImages:spriteArray];
 // Set the duration, or animation speed of our Sprite
[spriteViewTemp setAnimationDuration:duration];
// Without this, the animation would be stuck on frame1
// [spriteViewTemp startAnimating];

Sprite *tempImageView = spriteViewTemp;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
spriteViewTemp.center = CGPointMake(900,(arc4random()%(NSUInteger)(1000 - tempImageView.image.size.width)) + (tempImageView.image.size.width / 2)); 
}else if (IS_IPHONE_5){
spriteViewTemp.center = CGPointMake(490,(arc4random()%(NSUInteger)(560 - tempImageView.image.size.width)) + (tempImageView.image.size.width / 2)); 
}else{
spriteViewTemp.center = CGPointMake(400,(arc4random()%(NSUInteger)(470 - tempImageView.image.size.width)) + (tempImageView.image.size.width / 2)); 
}

// Set the position of our Sprite
// Add the Sprite to the view sent in 'sender'
[sender addSubview:spriteViewTemp];
// Clean up
// Set the integer value of the Sprite (this is optional, depends if your app needs it)
[tempImageView setIValue:val];
// Finally, return the new animated Sprite
 return tempImageView;
}
@end
Picture
coindropanimation.zip
File Size: 81 kb
File Type: zip
Download File

1 Comment
How To Make $100 A Day link
1/3/2016 12:42:24 am

They entertain us by tv shows or movies that we watch everyday with that we would not know what to do .

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Delivered by FeedBurner

    RSS Feed

    Archives

    December 2019
    August 2018
    January 2018
    December 2017
    November 2017
    October 2017
    August 2017
    April 2017
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014


    ​​Categories

    All
    Affiliate Marketing
    Alexa Rank
    Apple's Latest Updates
    Blog Tips
    Cocos2d X
    Cocos2d-x
    Google AdSense Tips
    Grab-some-ultimate-ideas
    How-to-create-a-twinkling-star-background-effect-in-ios
    In-App Purchase Tutorial In Cocos2d-x (C++) Using SDKBOX
    Ios Interview Questions And Answers
    IOS Multiple Choice Questions And Answers
    Objective C
    Online Business
    Python
    Secrets To Effective IPhone App Marketing
    SEO Tips
    Swift Interview Questions
    Swift Tutorials
    Top 10 Articles Objective C
    Top 10 Articles-Objective-C
    Top 10 Popular Movies Ever
    Top 10 Popular Things To Know
    Top 10 Ultimate Issues Xcode
    Top 400 IOS Interview Questions
    Top IOS Sample Projects To Learn From
    Top Secrets To App Marketing
    UICollectionView
    Unity 3D
    Xcode

WELCOME TO HUNTMYIDEAS

Picture
I am Jitendra Gochhayat,an iOS Developer,Designer,blogger,
​from Odisha,India.
I write about ​​​blog tips and,
Make money online Tips,
​Objective C tutorials
SUSCRIBE TO NEWSLETTER

    Subscribe to this blog and receive notifications of new posts by email

Suscribe
Picture
Picture
Picture
Picture
Picture
HuntMyIdeas-2016 Powered By Weebly
Picture
Powered by Create your own unique website with customizable templates.
Powered by
Powered by