Reputation: 21
i want the UIImage to move on the screen vertically downwards and when it reaches to the end it should again start from the top. how can i do it???
please help Thanks
Upvotes: 2
Views: 2037
Reputation: 8973
Assuming your UIImage is in a UIImageView and the image view is 320 x 480 in size...
Your animation block can call a method when it is complete. This method resets the position of your UIImageView and then starts the animation over.
Animation Block:
-(void)animate {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myCallback:finished:context:)];
CGRect frame = yourImageView.frame;
frame.origin = CGPointMake(0, 480);
yourImageView.frame = frame;
[UIView commitAnimations];
}
Callback:
(void)myCallback:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
CGRect frame = yourImageView.frame;
frame.origin = CGPointMake(0, 0)
yourImageView.frame = frame;
[self animate];
}
Upvotes: 1
Reputation: 21
This is how i wrote my code moving.h
#import <UIKit/UIKit.h>
@interface movingViewController : UIViewController{
UIImageView *imageView1;
}
@property (retain , nonatomic) UIImageView *imageView1;
@end
moving.m
#import "movingViewController.h"
@synthesize imageView1;
-(void) animate {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myCallback:finished:context:)];
CGRect frame = imageView1.frame;
frame.origin = CGPointMake(0, 480)
imageView1.frame = frame;
[UIView commitAnimations];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)myCallback:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
CGRect frame = imageView1.frame;
frame.origin = CGPointMake(0, 0)
imageView1.frame = frame;
[self animate];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];}
- (void)viewDidUnload {}
- (void)dealloc {
[imageView1 dealloc];
[imageView1 release];
[super dealloc];
}
@end
Im sorry to ask simple questions but im very new to Xcode
is that the correct way
Upvotes: 0