gpt4 book ai didi

iOS 布局动画在 GMSMapView 拖动时触发时忽略持续时间

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:53 25 4
gpt4 key购买 nike

您可以在下面比较两个 gif 时看到问题。 “收缩”和“拉伸(stretch)”动画都基于约束操作,并且 [self layoutIfNedeed] 放置在 -animateWithDuration block 内。如您所见,本地图不移动时,它会按预期工作。但是当您开始拖动 map 时,“收缩”动画会立即发生。如果仔细观察,您可能会注意到 cornerRadius 动画仍然有效。这告诉我它可能与 map 有关(里面有 ScrollView ?不知道谷歌地图是如何工作的)调用它自己的布局 block 干扰我的动画。或者可能是因为 cornerRadius 动画是使用 CABasicAnimation 完成的,而不是 UIView 动画。

动画 InfoView 不是 mapView 的 subview 。当 mapView 调用内部布局方法时,不确定它是否会影响我的 infoView 的布局。

我已经尝试了所有选项的组合 UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions 只是为了看看它是否有帮助。它没有。

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

知道是什么原因造成的以及如何使用自动布局动画解决这个问题吗?

更新

我试过直接为帧设置动画 - 结果是一样的。所以它与自动布局无关。当前 View 动画似乎由于某种原因停止了。

如果我用 CABasicAnimation 替换我的 UIView 动画 block ,它就像一个魅力。

我被要求发布一些动画代码:

- (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) {
//
}];


}

enter image description here enter image description here

最佳答案

我就此问题向 Google ( https://code.google.com/p/gmaps-api-issues/issues/detail?id=10349 ) 提出了一个错误,这是他们的回应:

Our understanding is that this is happening because the mapView:willMove: call is being made while already inside a CoreAnimation transaction. Our suggested work around is to wrap the UIView.animateWithDuration call within a dispatch_async back to the main thread. Something along the lines of:

dispatch_async(dispatch_get_main_queue(), ^{ // animation block here. });

Does that help?

将 UIView.animateWithDuration block 放在 dispatch_async block 中对我有用。

关于iOS 布局动画在 GMSMapView 拖动时触发时忽略持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com