MKMapview freezes when zoomEnabled=NO and call setRegion (iPhone SDK)
I am a beginner in iPhone development and I have come across a problem with MKMapView
. First let my describe how to reproduce the problem.
- Create a view-based application
- In Interface Builder, add a MapView that cover the whole view area
- Add a
UIButton
over the Mapview (size 50x50 is fine, put it in a corner) - Associate the MapView in IB with a MapView reference in the code
- Associate the
UIButton
to an handling method (touch down).
Here's the code for the controller (MapTest3ViewController.h)
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapTest3ViewController : UIViewController {
MKMapView *myMapView;
}
@property (nonatomic,retain) IBOutlet MKMapView *myMapView;
- (IBAction) zoomClicked:(id)sender;
@end
(MapTest3ViewController.m)
#import "MapTest3ViewController.h"
@implementation MapTest3ViewController
@synthesize myMapView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//myMapView.zoomEnabled = NO;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (IBAction) zoomClicked:(id)sender
{
// when zoom button is clicked, zoom on a specific region
CLLocationCoordinate2D locationCoordinate2D;
locationCoordinate2D.latitude = 35.6994;
locationCoordinate2D.longitude = 139.78;
MKCoordinateSpan coordinateSpan;
coordinateSpan.latitudeDelta = 1;
coordinateSpan.longitudeDelta = 1;
MKCoordinateRegion coordinateRegion;
coordinateRegion.center = locationCoordinate2D;
coordinateRegion.span = coordinateSpan;
[myMapView setRegion:coordinateRegion animated:YES];
}
@end
I have set scrollEnabled=YES, zoomEnabled=YES and showUserLocation=YES in IB. The application WORKS fine. I can zoom using pinching, I can scroll, whenever I push the "Zoom" button the view area moves to the region defined in zoomClicked.
The problem
When I set zoomEnabled=NO
in viewDidLoad
, I can no longer zoom using pinching gestures which is fine. However, if I "play" with the map, scrolling, trying to zoom(which of course doesn't work), then push the zoom button the map freezes and I can no longer scroll or do anything.
Again, how to replicate the problem (zoomEnabled=NO
)
After application loads, the map of the entire earth appears. Do some pinching gestures in and out, scroll the map. (Zoom doesn't work which 开发者_JAVA百科is expected)
Push the zoom button which should set the map the a specific region (in the code Tokyo, Japan) -> the map freezes.
My setup
iPhone OS 4.0.1/iPhone 3GS/XCode 3.2.3 64bit/Testing done on the phone itself.
Any help would be greatly appreciated. Thanks.
精彩评论