开发者

Mysterious borders during MKMapView animation

开发者 https://www.devze.com 2023-01-17 10:50 出处:网络
I have a UIView in which I flip between a UITableView and a MKMapView. The MKMapView is created at runtime and animated in the following function:

I have a UIView in which I flip between a UITableView and a MKMapView. The MKMapView is created at runtime and animated in the following function:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:(self.mapView == nil ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft)
                       forView:self.topView cache:YES];
// create new map view if necc.
if (self.mapView == nil)
{
    self.mapView = [[VTMapView alloc] initWithFrame:self.topView.bounds];
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;
    mapView.scrollEnabled = YES;
    mapView.zoomEnabled = YES;
    mapView.showsUserLocation = YES;
    }
// map visible? show or hide it
if (![self isMapVisible])
{
    tableView.hidden = YES;
    [self.topView insertSubview:mapView aboveSubview:self.tableView];
    mapLoadCount = 0;
} else {
    tableView.hidden = NO;
    [mapView removeFromSuperview];
}
[UIView commitAnimations];

The first time it works fine, but in future runs there are horizontal bars on the top and bottom of the map view during the animation. It开发者_运维问答 looks something like this:

Mysterious borders during MKMapView animation

I've tried playing with the cache setting, removing other views, etc. It doesn't happen in the simulator but it happens on OS 4.1.x and 3.1.x.

If I don't hide the tableView, I see bits of the table instead of the grey bars, so I think the mapview is being resized incorrectly during the flip.


Change this line:

UIView setAnimationTransition:(self.mapView == nil ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft)
                   forView:self.topView cache:YES];

To this line:

UIView setAnimationTransition:(self.mapView == nil ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft)
                   forView:self.topView cache:NO];

And that is the answer.

0

精彩评论

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