0

I am coding in iOS.

I have an NSArray, which contains a few MKMapCameras. I want to display MKMapCameras from the array one after another.

I put a while loop and used [self.mapView setCamera:nextCamera animated:YES];

However, this is only showing the first and the last views. Everything in between is going too fast.

I want to slow down the movement of each camera. Is there a way to achieve it using CATransaction or using any other animation tricks. If so, could you please show me an example code?

Want to give an update... I tried below code. But it isn't working... Camera movements are fast as I mentioned earlier.

[CATransaction begin];
[CATransaction setAnimationDuration:5.5];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[CATransaction setCompletionBlock:^{
    [self.mapView setCamera:nextCamera animated:YES];
}];
[CATransaction commit];
4

2 に答える 2

3

WWDC の「Putting MapKit in Perspective」ビデオによると、マップ カメラを順番にアニメーション化するために完了ハンドラーを使用するアプローチは避ける必要があります。代わりに、マップ ビューにデリゲートを設定し、 regionDidChangeAnimated: 呼び出しをリッスンして、シーケンス内の次のカメラをトリガーする必要があります。このようにして、カメラの動きの速度を animateWithDuration で制御できます。

-(void)flyToLocation:(CLLocationCoordinate2D)toLocation {


    CLLocationCoordinate2D startCoord = self.mapView.camera.centerCoordinate;

    CLLocationCoordinate2D eye = CLLocationCoordinate2DMake(toLocation.latitude, toLocation.longitude);


    MKMapCamera *upCam = [MKMapCamera cameraLookingAtCenterCoordinate:startCoord
                                                        fromEyeCoordinate:startCoord
                                                              eyeAltitude:80000];


    MKMapCamera *turnCam = [MKMapCamera cameraLookingAtCenterCoordinate:toLocation
                                                        fromEyeCoordinate:startCoord
                                                              eyeAltitude:80000];

    MKMapCamera *inCam = [MKMapCamera cameraLookingAtCenterCoordinate:toLocation
                                                        fromEyeCoordinate:eye
                                                              eyeAltitude:26000];

    self.camerasArray = [NSMutableArray arrayWithObjects:upCam, turnCam, inCam, nil];

    [self gotoNextCamera];

}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    [self gotoNextCamera];
}

-(void)gotoNextCamera {

    if (self.camerasArray.count == 0) {
        return;
    }

    MKMapCamera *nextCam = [self.camerasArray firstObject];
    [self.camerasArray removeObjectAtIndex:0];

    [UIView animateWithDuration:3.0 animations:^{
        self.mapView.camera = nextCam;
    }];

}
于 2013-10-28T14:05:06.793 に答える