我在添加一些功能

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated


- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

我希望在地图区域更改时调用它。

当设备更改方向时,如何防止调用这些委托方法?

最佳答案

添加属性BOOL didRotate
然后添加类似

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    self.didRotate = YES;
}


- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
    if(self.didRotate) return;
}


- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    if(self.didRotate) {
        self.didRotate = NO;
        return;
    }
}

关于ios - 防止在设备旋转时调用MKMapViewDelegate方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17368385/

10-12 03:46