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;
}];
Related
I added in the button click event:
[UIView beginAnimations:nil context:nil];
sender.titleLabel.font = [UIFont systemFontOfSize:18];
[UIView commitAnimations];
The animation is not working. But if I remove [UIView commitAnimations];, the animation works. Why?
If I don't add [UIView commitAnimations];, what will happen?
Why you are not using this for view animations?
[UIView animateWithDuration:1.0 animations:^{
// place your animations code here
}];
Note: please visit this url and see the section What can be animated. Only few properties can be used for animations
https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
Try this, it will help. In the example below, viewObject may be label in your case.
[UIView animateWithDuration:1.0 animations:^{
viewObject.transform = CGAffineTransformMakeScale(1.5, 1.5);
}];
Update, SOLVED
Sorry for my english, but i will do my best.
I have a problem with a button flip animation.
I want the UIButtons to fill the UIView. But how do i do that?
Here is my problem.
I have two UIButtons in a UIView.
When i press the first button it will flip correctly but when i press the second button that it have flipped to the UIView is still the same size but the UIButton image is changing size to the original size of the image and it also move the image to the upper left corner off the view controller. The same thing will repeat every time it flip.
Here is the flip animation code.
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.btn1 removeFromSuperview];
[buttonContainer addSubview:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.btn2 removeFromSuperview];
[buttonContainer addSubview:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
Have a nice day and thanks for any help!
I solved the problem like this
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
I solved the problem
See my update code.
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];
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.
I tried animating a sequence of UIViews from a mutable array to simulate this animation
for(int k = 0; k< [imageViewCarrier count] ; k++){
UIView *transformingView = [imageViewCarrier objectAtIndex:k];
[UIView animateWithDuration:30.0 animations:^{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30.0];
[UIView setAnimationDelegate:self];
[UIView transitionFromView:transformingView toView:splicedImageView duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
[UIView commitAnimations];
}completion:^(BOOL finished){
NSLog(#"Transition done");
}];
}
The animation seems to be too fast. Any suggestions on this. Did search some documentation but couldn't figure it out. Some help would be greatly appreciated!
Hm, I think you might be doing it the wrong way. If memory serves me, when using [UIView animinateWithDuration:animiations:completion:], you shouldn't call [UIView beginAnimations:nil context:NULL]; and [UIView commitAnimations]; or setAnimationDelegate: or setAnimationDuration: for that matter, since they are the old way of animating views that you had to use before the block-based methods were introduced.
I'd try leaving those out and see what happens. Also, note that the duration parameter is in seconds, so 30.0 seems a bit too long.
And just a style note: the "proper" Objective-C way to iterate through a collection is as follows:
for(UIView* view in imageViewCarrier){
[view doSomething];
}