使用Animation更改GMSCircle半径

时间:2014-04-11 15:40:41

标签: ios google-maps-sdk-ios

我正在使用Google Maps iOS sdk作为我的应用。在我的应用中,用户可以绘制围栏(圆圈),之后可以编辑以更改和调整圆的半径。 它适当调整大小,但是当半径值改变它的瞬间,而不是像地图放大/缩小的平滑动画。它是否可以用ios的最新GMaps sdk实现?

显然,这是不可能的,因为我看到的是GMSCircle继承自GSOOverlay,它是NSObject的孩子,所以它的defineltly不是一个视图,而是用某个层或类似的东西绘制叠加。

任何帮助都表示赞赏.. !!

谢谢.. !!

3 个答案:

答案 0 :(得分:2)

我发现你可以改变半径,圆圈也会改变。 所以我写了一个帮助类来做这个:

@interface TAMapCircle : GMSCircle
{
    CLLocationDistance _from;
    CLLocationDistance _to;
    NSTimeInterval _duration;
}
@property (nonatomic, copy) void(^handler)();
@property (nonatomic, strong) NSDate * begin;
@end

@implementation TAMapCircle
// just call this
-(void)beginRadiusAnimationFrom:(CLLocationDistance)from
                             to:(CLLocationDistance)to
                       duration:(NSTimeInterval)duration
                completeHandler:(void(^)())completeHandler {

    self.handler = completeHandler;
    self.begin = [NSDate date];
    _from = from;
    _to = to;
    _duration = duration;

    [self performSelectorOnMainThread:@selector(updateSelf) withObject:nil waitUntilDone:NO];
}

// internal update
-(void)updateSelf {

    NSTimeInterval i = [[NSDate date] timeIntervalSinceDate:_begin];
    if (i >= _duration) {
        self.radius = _to;
        self.handler();
        return;
    } else {
        CLLocationDistance d = (_to - _from) * i / _duration + _from;
        self.radius = d;
        // do it again at next run loop
        [self performSelectorOnMainThread:@selector(updateSelf) withObject:nil waitUntilDone:NO];
    }
}
@end

希望我的回答可以提供帮助。

答案 1 :(得分:1)

我使用CADisplayLink做了类似的事情。它使得在GMSMapView中进行简单动画变得非常容易。

https://developer.apple.com/library/prerelease/ios/documentation/QuartzCore/Reference/CADisplayLink_ClassRef/index.html

答案 2 :(得分:0)

您需要在UIView动画块中包装您尝试制作的动画更改。这在iOS SDK的最新版本中已更改,方法签名为[UIView beginAnimation:]。包装您在此块中所做的任何更改,它们将由UIKit设置动画。如果这不起作用,您可以使用CoreAnimation次交易进入较低级别。