我正在添加一些功能
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated和
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated我希望在更改地图区域时调用此方法。
如何防止这些委托方法在设备更改其方向时被调用?
发布于 2013-06-28 23:38:38
添加属性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;
}
}发布于 2013-06-28 23:48:10
当地图视图的框架更改时,将调用这些委托方法。由于自动布局约束或自动调整蒙版大小,框架可以在旋转时更改。因此,一种解决方案是保持地图视图框架不变。
您还可以尝试在界面方向更改时取消设置代理。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
_mapView.delegate = nil;
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
_mapView.delegate = self;
}https://stackoverflow.com/questions/17368385
复制相似问题