I currently animate two UILabel as such:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[_tempDescriptionLabel setAlpha:1];
[UIView commitAnimations];
However, I want to show the first label _temperatureLabel then once that is done animating (or maybe halfway through) start animating the second label _tempDescriptionLabel.
as I said I'll answer:
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//set alpha 1 for first UILabel
_temperatureLabel.alpha = 1;
} completion:^(BOOL finished){
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//when finished enter here
//set alpha 1 for second UILabel
_tempDescriptionLabel.alpha = 1;
} completion:^(BOOL finished){
}];
}];
remember to add QuartzCore framework, and add #import <QuartzCore/QuartzCore.h>
For doing halfWay or any other mid way time,
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[UIView commitAnimations];
[self performSelector:#selector(halfWayStart:) withObject:nil afterDelay:1.0];
-(void)halfWayStart:(id)object{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_tempDescriptionLabel setAlpha:1];
[UIView commitAnimations];
}
so, changing the afterDelay time value in performSelector call will help you to start other animation any time.
Related
I have managed to make the "view" move once. I need for it to stay 1 second in same place and then move back again to initial place. How would I add the rest of the code for this? (This won't be a loop, only done once)
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(160,30)];
} completion:nil];
Use the completion block to do another animation:
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(160,30)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 delay:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(orignalX, originalY)];
} completion:nil];
}];
I am using this code to change between 2 UIView:
UIViewAnimationOptions animationType = UIViewAnimationOptionTransitionFlipFromLeft;
[UIView transitionFromView:self.playlistTableView toView:self.playerView duration:0.5 options:animationType completion:^(BOOL finished){
[self.containerView sendSubviewToBack:self.upperView];
[self.containerView sendSubviewToBack:self.playerView];
self.isPlaylistVisible = !self.isPlaylistVisible;
isControlsHidden = NO;
}];
And i noticed a strange behavior, that when i made the flip the height of the self.playerView loosing 20px and after one second it's increase back to the normal frame size.
I try to change the animationType to UIViewAnimationOptionLayoutSubviews and now when i change between the view this behavior is not occur.
Any idea what can be the issue?
Please try this code.
[self.upperView setHidden:YES];
[self.playerView setHidden:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.playerView];
For getting reverse case
[self.upperView setHidden:NO];
[self.playerView setHidden:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.upperView];
In my app I move a button with this code:
[UIView beginAnimations:#"timerView" context:nil];
[UIView setAnimationDuration:0.5];
[timerView setCenter:CGPointMake(967, 80)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
but I want that the animation decelerate first to arrive to the point, how can I do it?
Add this line,
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
I have a simple UIViewAnimation that is called once my view is loaded.
However no matter what I place as the value for delay, it is ignored and the animation plays instantly.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:100.0];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(faceRight:finished:context:)];
_chooseLabelContainer.center = CGPointMake(originalCenter.x, 0 - _chooseLabelContainer.frame.size.height);
[UIView commitAnimations];
Update: As a test I've mangeled this scenario and below the non-delayed animation happens instantly, but the one within the dispatch queue animates overtime as expected!
UIView* objectToAnimate = self.hudController->_chooseLabelContainer;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[UIView animateWithDuration:5.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
NSLog(#"Start Dispatch %#", NSStringFromCGPoint( objectToAnimate.center ) );
objectToAnimate.center = CGPointMake(objectToAnimate.center.x, objectToAnimate.center.y+90);
}completion:^(BOOL done){
NSLog(#"Done Dispatch");
}];
});
[UIView animateWithDuration:5.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
NSLog(#"Start %#", NSStringFromCGPoint( objectToAnimate.center ) );
objectToAnimate.center = CGPointMake( objectToAnimate.center.x, objectToAnimate.center.y+30);
}completion:^(BOOL done){
NSLog(#"Done");
}];
This might not solve your problem, but as of iOS 4 Apple recommends you use UIView animation blocks:
[UIView animateWithDuration:100.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_chooseLabelContainer.frame = CGPointMake(originalCenter.x, 0 - _chooseLabelContainer.frame.size.height);
}completion:^(BOOL done){
[self faceRight:finished:context]; //will of course generate errors since I don't know what arguments to pass.
}];
I've been trying to fade in an MKMapView when we have successfully found the address, and fade out the view when long & lat == 0. I have the code in the delegate:
- (void)didCompleteMapsRequestWithLatitude:(double)latitude andLongitude:(double)longitude
Simple actions work as expected (e.g., setHidden:YES or setHidden:NO) at the correct time.
My problem is that while the fade in seems to work well every time it's called, the fade out animation doesn't appear to happen. It's as if the only call is setHidden:YES.
My fade code is as follows:
//no location found
if (location.latitude == 0 && location.longitude == 0)
{
//fade out
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[self.map setAlpha:0.0];
[UIView commitAnimations];
[self.map setHidden:YES];
}
//we found the location on the map
else
{
[self.map setHidden:NO];
//fade in
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[self.map setAlpha:1.0];
[UIView commitAnimations];
}
Note I get the same behaviour using animation blocks with iOS 4.0.
Any thoughts?
Thanks
I think you need to run [self.map setHidden:YES] when the animation completed, like this:
[UIView animateWithDuration:1.0
animations:^{
self.map.alpha=0.0;
}
completion:^(BOOL finished){
self.map.hidden=YES;
}];