2013-10-03 55 views
5

我想要獲得它,以便在旋轉iOS 7地圖時註釋隨相機標題一起旋轉。想象一下,我有任何時候都必須指向北方的針註釋。在iOS 7地圖相機旋轉上更新地圖註釋

這看起來很簡單,首先,應該有一個MKMapViewDelegate用於獲取相機旋轉,但沒有。

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

我使用志願也試過:

我使用地圖代表們然後查詢地圖視圖的camera.heading對象,但首先這些代表似乎只是之前和旋轉手勢之後,曾經一度被稱爲嘗試在camera.heading對象上,但這不起作用,並且相機對象似乎是某種只在旋轉手勢完成時才更新的代理對象。

到目前爲止,我最成功的方法是添加一個旋轉手勢識別器來計算旋轉增量,並將其與區域更改代表開始時報告的攝像頭標題一起使用。這很有用,但在OS 7中,您可以「輕拂」您的旋轉手勢,並增加了我無法跟蹤的速度。有沒有辦法實時追蹤攝像頭的方向?

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated 
{ 
    heading = self.mapView.camera.heading; 
} 

- (void)rotationHandler:(UIRotationGestureRecognizer *)gesture 
{ 
    if(gesture.state == UIGestureRecognizerStateChanged) { 

     CGFloat headingDelta = (gesture.rotation * (180.0/M_PI)); 
     headingDelta = fmod(headingDelta, 360.0); 

     CGFloat newHeading = heading - headingDelta; 

     [self updateCompassesWithHeading:actualHeading];   
    } 
} 

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 
{ 
    [self updateCompassesWithHeading:self.mapView.camera.heading]; 
} 

回答

3

不幸的是,蘋果公司並未給出任何地圖信息的實時更新。您最好的選擇是設置一個CADisplayLink,並在更改時更新所需的任何內容。像這樣的東西。

@property (nonatomic) CLLocationDirection *previousHeading; 
@property (nonatomic, strong) CADisplayLink *displayLink; 


- (void)setUpDisplayLink 
{ 
    self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkFired:)]; 

    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; 
} 


- (void)displayLinkFired:(id)sender 
{ 
    double difference = ABS(self.previousHeading - self.mapView.camera.heading); 

    if (difference < .001) 
     return; 

    self.previousHeading = self.mapView.camera.heading; 

    [self updateCompassesWithHeading:self.previousHeading]; 
} 
+0

Thanks @Ross,似乎這是唯一的選擇。令人沮喪。我可能會提交一個錯誤報告。 – Electron