【发布时间】:2015-05-22 14:16:50
【问题描述】:
您可以在下面比较两个 gif 时看到问题。 “收缩”和“拉伸”动画都基于约束操作,[self layoutIfNedeed] 放置在 -animateWithDuration 块内。如您所见,当地图不移动时,它会按预期工作。但是当您开始拖动地图时,“缩小”动画会立即发生。如果您仔细观察,您可能会注意到cornerRadius 动画仍然有效。这告诉我它可能与地图有关(里面的滚动视图?不知道谷歌地图是如何工作的)调用它自己的布局块会干扰我的动画。也可能是因为cornerRadius 动画是使用CABasicAnimation 完成的,而不是UIView 动画。
Animated InfoView 不是 mapView 的子视图。不确定当 mapView 调用内部布局方法时它是否会影响我的 infoView 的布局。
我已经尝试了所有组合 UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionOverrideInheritedOptions 的选项,看看它是否有帮助。它没有。
我想我可以直接克服这个操纵框架而不是操纵约束,它对用户来说看起来是一样的,但我觉得使用约束要优雅得多。我尽量避免操纵框架并使用自动布局。
任何想法是什么导致了这个问题以及如何使用自动布局动画来解决这个问题?
更新
我尝试过直接为帧设置动画 - 结果是一样的。所以它与自动布局无关。似乎当前视图动画由于某种原因停止了。
如果我用 CABasicAnimation 替换我的 UIView 动画块,它就像一个魅力。
我被要求发布一些动画代码:
- (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) {
//
}];
}
【问题讨论】:
-
你能发布一些关于你的动画的代码吗?
-
我发布了缩小动画的代码。
标签: ios google-maps animation autolayout