Controlling Animation Duration in Google Maps for iOS

前端 未结 4 1567
广开言路
广开言路 2021-02-02 10:16

The documentation for Google Maps for iOS states that:

Call one of several methods that allow you to animate the camera moving to a new location. You can

相关标签:
4条回答
  • 2021-02-02 10:16

    for Swift 3.0:

    CATransaction.begin()
    CATransaction.setValue(1.5, forKey: kCATransactionAnimationDuration)
    // your camera code goes here, example:
    // mapView.animate(with: update)
    CATransaction.commit()
    

    The bigger the value (1.5 in this case), the slower the animation.

    0 讨论(0)
  • 2021-02-02 10:29

    I found the answer ... you can control the animation duration by wrapping one of the animate* methods in a CATransaction, like this:

       [CATransaction begin];
       [CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];
       // change the camera, set the zoom, whatever.  Just make sure to call the animate* method.
       [self.mapView animateToCameraPosition: [self newCamera]];
       [CATransaction commit];
    
    0 讨论(0)
  • 2021-02-02 10:35

    what a pitty that using the same methods you provided there is no way to know if the animation has ended.

    Yes I know, there is a CATransaction completion block using this method but it does simply not work! :(

    [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];
    
    [CATransaction setCompletionBlock:^{
    // ... whatever you want to do when the animation is complete
    }];
    
    [self.googleMapsView animateToCameraPosition:[GMSCameraPosition 
                        cameraWithLatitude:LATITUDE
                                 longitude:LONGITUDE
                                      zoom:ZOOM]];
    
    [CATransaction commit];
    

    And I can't use MapView:didIdle hack to know that the animation has ended because it will not be called if there is no camera position change.

    Anyone knows how to detect animateon has ended event?

    FOUND A THREAD ABOUT THIS (solved): CATransaction completion being called immediately

    0 讨论(0)
  • 2021-02-02 10:39

    Swift 2.0

    CATransaction.begin()
    CATransaction.setValue(NSNumber(float: 1.0), forKey: kCATransactionAnimationDuration)
    // change the camera, set the zoom, whatever.  Just make sure to call the animate* method.
    CATransaction.commit()
    
    0 讨论(0)
提交回复
热议问题