Created
March 17, 2013 11:43
-
-
Save taktamur/5181207 to your computer and use it in GitHub Desktop.
MKMapViewのKVOを利用して、初回1回だけ現在位置に
地図を移動させる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MKMapViewのlocationにaddObserverして、場所が更新されたら中心点に移動する。 | |
| // http://blog.syuhari.jp/archives/2035 | |
| [self.mapView.userLocation addObserver:self forKeyPath:@"location" options:0 context:NULL]; | |
| } | |
| - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
| self.mapView.centerCoordinate = self.mapView.userLocation.location.coordinate; | |
| // 一度しか現在地に移動しないなら removeObserver する | |
| [self.mapView.userLocation removeObserver:self forKeyPath:@"location"]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment