iOS布局animation在GMSMapView拖动时忽略持续时间

你可以看到比较两个GIF下面的问题。 “缩小”和“拉伸”animation都基于约束操作, [self layoutIfNedeed]放置在-animateWithDuration块内。 正如你所看到的,当地图没有移动时,它就像预期的那样工作。 但是,当您开始拖动地图时,“缩小”animation会立即发生。 如果仔细观察,您可能会注意到cornerRadiusanimation仍然有效。 这告诉我,它可能与地图(scrollView里面?不知道如何谷歌地图工作)调用它自己的布局块,干扰我的animation。 或者这可能是由于cornerRadiusanimation是使用CABasicAnimation而不是UIViewanimation完成的。

animationInfoView不是mapView的子视图。 不知道当mapView调用内部布局方法时它是否会影响我的infoView的布局。

我试过所有的选项结合UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions只是为了看看是否有帮助。 它不是。

我想我可以直接克服这个操纵框架,而不是操纵约束,它会看起来一样的用户,但我觉得使用约束是如此的优雅。 我尽量避免操纵框架,并使用自动布局。

任何想法是什么导致这一点,以及如何使用自动布局animation克服这个问题?

UPDATE

我试图直接animation框架 – 结果是一样的。 所以它与自动布局无关。 看起来像当前视图animation由于某种原因停止。

如果我用CABasicAnimationreplace我的UIViewanimation块,它就像一个魅力。

我被要求发布一些animation代码:

 - (void)shrink { if (!self.isStretched) return; self.stretched = NO; [self hideImageAndLabels]; [self.indicatorView startAnimating]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"]; animation.duration = duration; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.fromValue = @0; animation.toValue = @(shrinkedSize / 2.0); [self.layer addAnimation:animation forKey:@"cornerRadiusAnimationRounded"]; self.layer.cornerRadius = shrinkedSize / 2.0; self.heightConstraint.constant = shrinkedSize; self.widthConstraint.constant = shrinkedSize; self.positionYConstraint.constant = 0; self.triangleHeightConstraint.constant = 0; self.trianglePositionYConstraint.constant = 14; [UIView animateWithDuration:duration * 2 delay:0 usingSpringWithDamping:0.85 initialSpringVelocity:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ [self layoutIfNeeded]; } completion:^(BOOL finished) { // }]; } 

在这里输入图像说明在这里输入图像说明

我用Google( https://code.google.com/p/gmaps-api-issues/issues/detail?id=10349 )解决了这个问题,这是他们的回应:

我们的理解是,这是因为mapView:willMove:调用正在CoreAnimation事务中进行。 我们build议的解决方法是将dispatch_async中的UIView.animateWithDuration调用包装回主线程。 有些东西是:

dispatch_async(dispatch_get_main_queue(),^ {//animation块在这里。

这有帮助吗?

将UIView.animateWithDuration块放在dispatch_async块内。