开发者

MKMapView fade in but won't fade out via animation

开发者 https://www.devze.com 2023-03-25 23:44 出处:网络
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:

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 wo开发者_Go百科rk 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;
            }];
0

精彩评论

暂无评论...
验证码 换一张
取 消