I used some animations in my application.Its working fine.But while calling another animation previous animation comes old position.How to resolve these kind of problems.
Here my code:
CGRect frame = self.PickerView.frame;
frame.origin.x=0;
frame.origin.y=730;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
self.PickerView.frame=frame;
[UIView commitAnimations];
Related
I am working on an application which needs animations with imageView.
At starting the position of image is at CGPoint(735,112),on clicking the animation button it has to move to the left of the screen ie to point CGPoint(20,112) and hast to repeat the animation from left to right i.e to point CGPoint(735,112),has to stop after this. i am using the following Code.
CGRect newRect=cleanStrip.frame;
[UIView beginAnimations:#"animation1" context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatAutoreverses:YES];
newRect.origin.x=20;
cleanStrip.frame=newRect;
[UIView commitAnimations];
After repeating the animation the image view has to stop at it original position CGPoint(735,112).But the above code stops the image at CGPoint(20,112).
How can i stop the image at its original position after animation.
Thanks,
you can use block to start your animation
__block CGRect newRect=cleanStrip.frame;
__block int originx = newRect.origin.x;
[UIView animateWithDuration:2.0
animations:^{
newRect.origin.x=20;
cleanStrip.frame=newRect;
}
completion:^(BOOL finished){
[UIView animateWithDuration:2.0
animations:^{
newRect.origin.x=originx ;
cleanStrip.frame=newRect;
}];
}];
I'm drawing MKCircleView overlay on MKMapView. it works fine, except that I need to animate drawing of this overlay.
I know that I need to use:
[UIView beginAnimations:nil context:NULL];
[UIView commitAnimations];
,but I don't know where to put this animation code.
Thanks.
not sure what you're looking for.. but for example:
[UIView beginAnimations:#"fade" context:nil];
[UIView setAnimationDuration:0.6f];
theView.alpha = 0.0f;
theView.transform = CGAffineTransformMakeScale(0.01,0.01);
theView.alpha = 1.0f;
[UIView commitAnimations];
How does one remove the acceleration and deceleration animation that UIView Animations do?
If you don't understand what I mean, when an animation starts up it accelerates and then when it get to the end, it decelerated. I want the animation to be a constant speed.
Here is an example of what my code looks like (I MUST use the old animation ways).
-(void)animate:(NSString*)animationID finished:(BOOL)finished context:(void*)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:#selector(animateStop:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:3];
Motion.center = (*PathPoints)[Location];
[UIView commitAnimations];
}
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
I've got 2 methods in my class and in each I've got an animation. My question is, can I store these animations in one array or something and refer to them by beginAnimation:name? If yes, how can I do this?
thanks for help
-(void)hideMenu{
[UIView beginAnimations:#"HIDE_MENU" context:nil];
[UIView setAnimationDuration:0.38];
[UIView setAnimationDelay:0.12];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
self.frame = CGRectMake(0, -1 * self.frame.size.height, self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];
}
-(void)showMenu{
[UIView beginAnimations:#"SHOW_MENU" context:nil];
[UIView setAnimationDuration:0.38];
[UIView setAnimationDelay:0.12];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
self.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];
}
-(void)handleShowMenu:(NSNotification*)note{
[self showMenu];
}
-(void)handleHideMenu:(NSNotification*)note{
[self hideMenu];
}
You can't store UIView animations as they are not objects. Even with blocks animation api introduced in 4.0, animations are still just actions performed by static class methods. Closest thing you can do is store the blocks and reuse them, or just do what you are doing and keep compatibility with iOS versions older than 4.0.
If you really want to store your animations as objects, you should skip UIView animation and go a bit lower to Core Animation.
I am using core animation to flash intermediate scores (using UILabel) in a game on iPhone. I need it to repeat for certain count for a particular hit.
The score needs to be flashed for a particular count and then disappear.
So it should go from alpha 0.0 -> 1.0 -> 0.0
Below is the code with which I am trying to achieve this.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:repeatCount];
[UIView setAnimationRepeatAutoreverses:YES];
playerScore.alpha = 1.0f;
[UIView commitAnimations];
The problem is that after the animation is over, the alpha returns back to 1.0
Any suggestions?
I would use the more powerful animateWithDuration:delay:options:animations:completion: method on UIView. See View programming guide or UIView class reference
More specifically it could look like that: the method takes two blocks: one for the animation itself and one block which is execute once the animation is done. It maybe look a bit strange at first sight, but that is just the block syntax.
[UIView animateWithDuration:1.0 delay:0.f options:(UIViewAnimationOptionAutoreverse| UIViewAnimationOptionRepeat)
animations:^{
playerScore.alpha=1.f;
} completion:^(BOOL finished){
playerScore.alpha=0.f;
}];
This solution is for iOS version 4 or higher. If you want to target versions before that, you have to use a delegate callback. Set the selector to be executed when the animation is done like this:
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(flashingDidStop:finished:context:)];
//with the callback method
- (void)flashingDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
//code to execute in your case
playerScore.alpha = 0.f;
}
If you need this to work in iOS < 4.0 try this:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
playerScore.alpha = 0.0f;
}
...
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:repeatCount];
[UIView setAnimationRepeatAutoreverses:YES];
playerScore.alpha = 1.0f;
[UIView commitAnimations];