I found a solution to your problem, using Mark Amery's idea about traversing the MKMapView
instance subviews to find the compass, along with the use of gesture recognition to trigger the removal event.
To find the compass I printed out the description of the views and found that one of the views was an instance of MKCompassView
, this was obviously the compass.
I have come up with the following code that should work for you. It checks for a rotation gesture, and then removes the view in method triggered by the gesture event.
I have tested this method and it works well for me:
- (void)viewDidLoad
{
[super viewDidLoad];
UIRotationGestureRecognizer *rotateGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[self.mapView addGestureRecognizer:rotateGesture];
}
-(void)rotate:(UIRotationGestureRecognizer *)gesture
{
if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged) {
// Gets array of subviews from the map view (MKMapView)
NSArray *mapSubViews = self.mapView.subviews;
for (UIView *view in mapSubViews) {
// Checks if the view is of class MKCompassView
if ([view isKindOfClass:NSClassFromString(@"MKCompassView")]) {
// Removes view from mapView
[view removeFromSuperview];
}
}
}
}