UIImage to slide downwards using animation - iphone

How can implement image sliding down animation in ios app?
I've used this code:
imageview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],[UIImage imageNamed:#"img12.png"],[UIImage imageNamed:#"img13.png"],nil];
imageview.animationDuration = 10.00;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
But this is only a simple slide show.
Help me.

try with this code..
imageview = [[UIImageView alloc] initWithFrame:self.view.frame];
imageview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],[UIImage imageNamed:#"img12.png"],[UIImage imageNamed:#"img13.png"],nil];
imageview.animationDuration = 1.25;
imageview.animationRepeatCount = 10;
[imageview startAnimating];
[self.view addSubview:animationView];
[imageview release];

Please try following code
-(void) createNewImage {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],
[UIImage imageNamed:#"img12.png"],
[UIImage imageNamed:#"img13.png"],nil];
[imageView setAnimationRepeatCount:10];
imageView.animationDuration =1.5;
[imageView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:#selector(setLastImage:) userInfo:nil repeats:NO];
}
-(void)setLastImage:(id)obj
{
[imageView performSelectorOnMainThread:#selector(setImage:) withObject:[UIImage imageNamed:#"img12.png"] waitUntilDone:YES];
}

You can change the centre of UIImageView using imgVw.centre, you can update the centre with NSTimer. Vary the centre according to the screen, you can get screen height from
[[UIScreen mainScreen]bounds].size.height
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:#selector(updateTimer:)
userInfo:nil
repeats:YES];
- (void)updateTimer:(NSTimer *)theTimer {
//update centre;
imgVw.centre.y += 4;
// you can update the image also if needed use if case
imgVw.image = image2;
}

Related

Animate array of image and textview together in UIView

I want to aniate array of imageview and textview together in uiview.
Right now i am animating image view separate and textview separate which is not looking that good.
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
baseView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:252.0/255.0 blue:199.0/255.0 alpha:1.0];
[self.view addSubview:baseView];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 30, 200, 200)];
self.imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
nil];
// all frames will execute in 25 seconds
self.imageView.animationDuration = 20;
[self.imageView startAnimating];
[baseView addSubview:self.imageView];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 250, 300, 200)];
self.textView.textColor = [UIColor brownColor];
myArray = [[NSMutableArray alloc] initWithObjects:#"string1", #"string2", #"string3", #"string4", #"string5", ...., nil];
[NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:#selector(updateText:)
userInfo:nil
repeats:YES];
[baseView addSubview: self.textView];
- (void)updateText:(NSTimer *)theTimer
{
if (index < [myArray count])
{
self.textView.text = [self.myArray objectAtIndex:index];
index++;
}
else
index = 0;
[timer invalidate];
}
How i can animate both image view and textview together within UIView.
Thanks for help.
How about this,,
in your .h
NSArray *imgsArray;
NSArray *myArray;
int indx;
NSTimer *timer;
and start your animation
-(void)start{
imgsArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"1.png"],[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],nil];
myArray = [[NSMutableArray alloc] initWithObjects:#"string1", #"string2", #"string3", #"string4", #"string5", nil];
timer = [NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:#selector(updateText:)
userInfo:nil
repeats:YES];
}
- (void)updateText:(NSTimer *)theTimer
{
if (indx < myArray.count)
{
self.textView.text = [self.myArray objectAtIndex:indx];
self.imageView.image = [self.imgsArray objectAtIndex:indx];
indx++;
}
else
indx = 0;
}

delay imageviews xcode

I hit the play button 6 image views will be filled with the pressed images, I want it to view 1, wait 1 second,view2, wait one second etc.
which code should I be adding to:
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];
I tried this: but it doesn't work:
[self performSelector:#selector(GameViewController) withObject:nil afterDelay:1];
hope someone knows bye thanks
EDIT explaining my code more
-(IBAction)play {
[self performSelector:#selector(delay) withObject:nil afterDelay:5.0];
play.enabled=NO;
UIImage *img = [UIImage imageNamed:#""];
if (imageview7.image == nil) {
if([textview.text isEqualToString:labelsText.text]){
-(void)delay {
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];}
}
else {
-(void)delay {
[imageview7 setImage:imageview1H.image];
[imageview8 setImage:imageview2H.image];
[imageview9 setImage:imageview3H.image];
[imageview10 setImage:imageview4H.image];
[imageview11 setImage:imageview5H.image];
[imageview12 setImage:imageview6H.image];}
I guess you want to setImage on UIImageView one after the other after a delay.Here is the code for it.
Definition
#interface ViewController : UIViewController
{
NSMutableArray * imageViews;
NSMutableArray * images;
int count;
NSTimer * timer1;
}
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image;
-(void)update;
-(IBAction)setImageOnViewOneAfterOther;
#end
Definition
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image{
[imageView setImage:image];
}
-(void)update{
if (count < [imageViews count]) {
[self setImageForView:[imageViews objectAtIndex:count] withImage:[images objectAtIndex:count]];
count ++;
}else{
[timer1 invalidate];
}
}
-(IBAction)setImageOnViewOneAfterOther{
count = 0;
imageViews = [[NSMutableArray alloc] initWithObjects:img1v,img2v,img3v,img4v,img5v,img6v, nil]; // Set of all UIImageViews
images = [[NSMutableArray alloc] initWithObjects:img1,img2,img3,img4,img5,img6, nil];//Set of all UIImage's where img = [UIImage imageNamed:#"someImage1.png"];
timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(update) userInfo:nil repeats:YES];
}
Why not animate it?
UIImageView* animatedImageView = [[UIImageView alloc]init];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.gif"],
[UIImage imageNamed:#"2.gif"],
[UIImage imageNamed:#"3.gif"],
[UIImage imageNamed:#"4.gif"], nil]; //etc
animatedImageView.animationDuration = float([animatedImageView.animationImages count]);
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];

problem with animationImages array

here is my code :
-(void) createNewImage {
image.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"oeufgrisé.png"],
[UIImage imageNamed:#"abouffer_03.png"],
[UIImage imageNamed:#"boutonplay_03.png"],
[UIImage imageNamed:#"boutonpause_03.png"],
[UIImage imageNamed:#"abouffer_05.png"],
[UIImage imageNamed:#"mangeurcentremieu3_03.png"],nil];
[image setAnimationRepeatCount:10];
image.animationDuration =1.5;
[image startAnimating];
imageView = [[UIImageView alloc] initWithImage:image];
}
This code doesn't work, I don't know why. I have always this warning on line "imageView = [[UIImageView alloc] initWithImage:image];" :Incompatible ObjectiveC type struct UIImageView*' expected struct UIImage*' when passing argument 1 of initWithImage from distinct Objective C type
You can set animation images to UIImageView , and not to UIImage.
-(void) createNewImage {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"oeufgrisé.png"],
[UIImage imageNamed:#"abouffer_03.png"],
[UIImage imageNamed:#"boutonplay_03.png"],
[UIImage imageNamed:#"boutonpause_03.png"],
[UIImage imageNamed:#"abouffer_05.png"],
[UIImage imageNamed:#"mangeurcentremieu3_03.png"],nil];
[imageView setAnimationRepeatCount:10];
imageView.animationDuration =1.5;
[imageView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:#selector(setLastImage:) userInfo:nil repeats:NO];
}
-(void)setLastImage:(id)obj
{
[imageView performSelectorOnMainThread:#selector(setImage:) withObject:[UIImage imageNamed:#"mangeurcentremieu3_03.png"] waitUntilDone:YES];
}
If you are doing:
image.animationImages = [NSArray arrayWithObjects:
then image is an UIImageView (review the code where you allocate it). That is the reason why you get the error, since initWithImage expects an object of type UIImage:
- (id)initWithImage:(UIImage *)image
Either you did not mean image to be an image view, or possibly you don't need to allocate a second UIImageView in your method and can just use image.
Make sure that image is a UIImageView and not a UIImage. You can only create animationImages for UIImageViews.

Trouble loading 2 separate image sequences in the UIImageView

I don't know if this is possible, but I need to load one image sequence in the imageView and have it play only once, then unload that sequence and load the second image sequence into the same imageView control.
Here is the code I'm using for loading and playing the first sequence.
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:#"openingSeq0140.jpg"],nil];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
[self.view addSubview:imageView];
[super viewDidLoad];
I now want to load and play the second sequence into the same imageView control once it has played through once. I have tried if statements, even a do while loop to make sure that the animation was at least played once and decremented the counter 1 and passed the value to the imageView.animationRepeatCount to equal 0.
imageView.animationRepeatCount = 0;
I thought I could figure it out, but I'm missing something somewhere. I can get the second grouping of images to run or the first and then is just stops. I used a do while loop for that.
I used this to make it work:
SEL methodSelector = #selector(startSeqTwo);
[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:methodSelector userInfo:nil repeats:NO];
I used the selector after the first block of code to load the first sequence and called method:
-(void)startSeqTwo;
I have not done it but you could try using self performSelectorOnMainThread:(SEL) withObject:(id) waitUntilDone:(BOOL) function.
-(void)animateSequence{
[self performSelectorOnMainThread:#selector(animateFirstSequence) withObject:nil waitUnitilDone: YES];
[self performSelectorOnMainThread:#selector(animateSecondSequence) withObject:nil waitUnitilDone: YES];
}
-(void)animateFirstSequence{
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:#"openingSeq0140.jpg"],nil];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}
-(void)animateSecondSequence{
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:#"openingSeq0140.jpg"],nil];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}
Edit
You can also try checking if the UIImageView is stil animating and wait until finished to play another sequence. You would do it like this:
-(void)animateSequence{
//First sequence
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:#"openingSeq0140.jpg"],nil];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
while([imageView isAnimating])
//Do nothing
//second sequence
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:#"openingSeq0140.jpg"],nil];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}
SEL methodSelector = #selector(startSeqTwo);
[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:methodSelector userInfo:nil repeats:NO];
This worked.
I used the selector after the first block of code to load the first sequence and called method: -(void)startSeqTwo;

How can i create a UIImage from a UIImageView?

I am trying to implement an animation set of images on my application.
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"myImage1.png"],
[UIImage imageNamed:#"myImage2.png"],
[UIImage imageNamed:#"myImage3.png"],
[UIImage imageNamed:#"myImage4.gif"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];
Ok, but the problem is that i am using an API function to place a marker on a map.
That function is the following:
RMMarker *newMarker;
UIImage *blueMarkerImage = [UIImage imageNamed:#"marker.png"];
newMarker = [[RMMarker alloc] initWithUIImage:blueMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
[mapView.contents.markerManager addMarker:newMarker AtLatLong:position];
[newMarker release];
The problem is that "initWithUIImage:" only works with UIImage, not with UIImageView.
So, how can i solve it??
UPDATE: My new code that is not working:
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"marker0.png"],
[UIImage imageNamed:#"marker1.png"],
[UIImage imageNamed:#"marker2.png"],
[UIImage imageNamed:#"marker3.png"],
[UIImage imageNamed:#"marker4.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 10; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:[myAnimatedView image] anchorPoint:CGPointMake(0.5, 1.0)];
[mapView.contents.markerManager addMarker:newMarker AtLatLong:markerPosition];
You can try using image message from UIImageView:
newMarker =
[
[RMMarker alloc]
initWithUIImage:[myAnimatedView image]
anchorPoint:CGPointMake(0.5, 1.0)
];
Or, if what you need is creating a UIImageView then you can try:
UIImageView *newMakerImageView =
[[UIImageView alloc] initWithImage:
[
[RMMarker alloc]
initWithUIImage:yourImageHere
anchorPoint:CGPointMake(0.5, 1.0)
]
];
UIImageView *myAnimatedView = [UIImageView alloc]
That may just be a copy/paste error, but you forget the init.
UIImageView *myAnimatedView = [[[UIImageView alloc] initWithFrame:[self bounds]] autorelease]