animate an image like cardiogram - iphone

i have an image
i want to animate this image continuously i.e entering from left end of screen and exit at right end for this i'm using this code..
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:15];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
cardioImage1.frame = CGRectMake(330, 0, 320, 100);
[UIView commitAnimations];
This code animate images only for one time.
I want to make it continuous animation for certain time frame.
What can i do for that... please help me.
Thanks in advance.

You need to set some value to this property :
setAnimationRepeatCount
Perhaps use FLT_MAX for infinite loop

Related

How to implement UIViewAnimationOptionBeginFromCurrentState

I have a piece of audio & associated Play & Stop buttons, when the Play button is pressed I use an animation of a curser to denote at which point in the audio sample we are, at a given moment. Whenever the stop button is pressed I want my curser to return to its initial coordinates. I believe UIViewAnimationOptionBeginFromCurrentState might be the way to do this? My code for the initial animation is below, anyone have any tips on how to use UIViewAnimationOptionBeginFromCurrentState in order to send the cursor back to its original coordinates?
Thanks for any help in advance :)
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
yellowBar.frame = CGRectMake(310, 20, 5, 100);
[UIView commitAnimations];
If you are still using beginAnimations/commitAnimations, use setAnimationBeginsFromCurrentState:. Otherwise, you can pass UIViewAnimationOptionBeginFromCurrentState to animateWithDuration:delay:options:animations:completion: for the options parameter.
Brian is right, you have got two alternatives:
//Initialize newFrame here
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState //Multiple options
animations:^ {
[yourView setFrame: newFrame];
}
completion:^ (BOOL finished) {
}];
Or
//Initialize newFrame here
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[yourView setFrame: newFrame];
[UIView commitAnimations];
AFAIK you can only use that option with block-based animations (which you are encouraged to use anyway). You'd use the animateWithDuration:delay:options:animations:completion: method, described here.

iPhone: How to commit two animations after another

This is an absolute beginner's question (sorry), but I was wondering how to commit one animations and once it has ended to start another one. Imagine having an image moved from x=0 to x=300. Then you want to do animate the same image again, but this time from x=300 to x=330 so that it disappears from the screen.
The following code will only do the animation from x=300 to x=330 and will not commit the animation x=0 to x=300. I'm sure I don't get the concept of commitAnnimation and that this is obvious, but how would I do two animations after one another?
I know I could move the image straightaway to 330, but I don't want this as I need the first animation (x 0 - 300) to be in sync with another animation.
Here is my (wrong) code:
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)]; // Move imageView off screen
[UIView commitAnimations]; // End animations
Use the delegate method
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
to start something else when the first animation has finished. So put what you want to do next inside the animationDidStop:finished:context method, remember that the iphone is an event driven environment so linear code like you have above will simply kick off each animation at almost the same time.
EDIT:
I forgot to add that you need to set the animation delegate as well otherwise you won't get the event when the first one stops - see below;
Here's a full version of your code with the change - I'm using the abbreviated animationDidStop delegate as that's easier to understand and fine for this example.
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myFirstAnimationDidStop)];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
Then you just need a new method like this;
-(void) myFirstAnimationDidStop {
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)];
[UIView commitAnimations];
}
And for completeness, in your interface (.h) file you should add;
-(void) myFirstAnimationDidStop;
#selector is easy, it's just a way of pointing to another method - hopefully this example clarifies that.

iPhone effect hide slow object

i've a problem : in my app i've a UISlider. Its function is to set the volume of some files i've included. I want to do this thing : the slider will be hide when user tap the screen and will be not hide when the user retap the screen. But there were 2 problems :
1.- i want to use a slow hide effect, not from .alpha=0.0 to .alpha=1.0, but gradually
2.- i don't know what to do if user tap the screen when slider is going to hide or to show
Sorry for my english, i'm italian :)
Thanks
Use animations
// To hide the slider slowly
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
slider.alpha = 0.0;
[UIView commitAnimations];
// To show the slider
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
slider.alpha = 1.0;
[UIView commitAnimations];

animation effects : leaf falling down to ground

Need to figure some transformation codes to implement falling down naturally just like leaves falling down from tree.
Here are some codes, fly from one place to another place with some rotation angle.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:5.0];
[UIView setAnimationDelegate:self];
//[UIView setAnimationRepeatCount:1e100f]; //coutless
[UIView setAnimationRepeatCount:1]; // 1 time
//[UIView setAnimationRepeatAutoreverses:YES];
leaf2.frame = CGRectMake(LEAF2_X, LEAF2_Y, LEAF2_W, LEAF2_H);
leaf2.transform = CGAffineTransformMakeRotation(ANGLE);
[UIView commitAnimations];
See if the next 2 questions help:
What is the best way to make a bouncing ball animation with infinite loop on iPhone?
Mimic UIAlertView Bounce?

how to implement an iPhone view transition animation with both flipping and scaling?

how can I implement the animation we see in the iPhone Music app's coverflow screen? when you click on a small view, it flips and scales up to another view? how can I do this? I can use core animation to flip and scale a view, but how can I do the transition to another view? thanks
You need an UIView as Container for the two UIViews (frontside/backside) and then remove/add these from/to the container as subviews while doing the animations in between:
UIView *flipContainer;
UIView *frontSide;
UIView *backSide;
//...
-(void)turnUp
{
[backSide removeFromSuperview];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:flipContainer cache:YES];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeScale(1.2, 1.2);
flipContainer.transform = transform;
[UIView commitAnimations];
[flipContainer addSubview:frontSide];
}
-(void)turnDown
{
[frontSide removeFromSuperview];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipContainer cache:YES];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeScale(1, 1);
flipContainer.transform = transform;
[UIView commitAnimations];
[flipContainer addSubview:backSide];
}
I'm trying the exact code you are doing - I get a zoom effect but no turn over. The only difference is that right before the turnUp code I add the flipContainer (with back showing) so then it can be flipped over.
// construct animation container
self.flipContainer = [[FlipContainer alloc] init];
[self.flipContainer.view setFrame:CGRectMake(clickedSquareX, clickedSquareY, 200, 200)];
[self.flipContainer.view addSubview:self.backside.view];
// add animation container
[self.myParentView.view addSubview:self.flipContainer.view];
// PROCEED to your turnUp code
The reason I'm doing this is I have a bunch of images in a horizontal UIScrollView and so to 'simulate' a 200x200 image flipping over and zooming to show detail I add my flipContainer with the backside showing the exact image over the exact spot of the pressed image. It should work shouldn't it? A bit confusing to me is the first line of your turnUp code you do:
[backSide removeFromSuperview];
..which would remove the view I just added.
I'm not sure if this is the right spot to put this question in - sorry if it isn't!