gpt4 book ai didi

iphone - 控制iOS6中MKMapView的动画速度

转载 作者:可可西里 更新时间:2023-11-01 03:05:18 26 4
gpt4 key购买 nike

我正在尝试在 map View 中跟随汽车。

此代码应以相同的速度为汽车和 map 设置动画,以便注释 View 始终出现在中心:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationBeginsFromCurrentState:YES];

[car setCoordinate:coord];
[mapView setCenterCoordinate:coord];

[UIView commitAnimations];

它在 iOS 5 中运行良好。在 iOS 6 中, map 不再有动画,但汽车有动画。

我尝试了[mapView setCenterCoordinate:co animated:YES],但是我无法控制动画速度。它将始终以默认持续时间 (0.2s) 进行动画处理。

最佳答案

我今天遇到了同样的问题。我认为问题不依赖于 MKMapView,而是 ios6 管理动画的(新)方式。

似乎在 ios6 中,如果动画在前一个动画完成之前发生(取决于运行循环),则旧动画会被新动画打断。我认为只有在(新的)使用“beginsFromCurrentState”选项或属性(取决于您是否使用基于 block 的动画)时才会发生这种情况。

可以肯定的是,我认为您应该尝试使用基于 block 的动画来查看您的动画是否真的被另一个动画打断了。

此代码必须与您的相同,并允许您查看动画是否已被中断或取消(如果“finished”为 false):

[UIView animateWithDuration:1.0 delay:0.0f options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState) animations:^{

[car setCoordinate:coord];
[mapView setCenterCoordinate:coord];

} completion:^(BOOL finished){
NSLog(@"has not been interrupted : %d", finished);
}];

(在 iOS < 6 中,"finished"应该是真的...)

在我的例子中,我的动画似乎被以下 UIViewController 的方法打断了,这些方法由系统在动画 block 中执行,打断了我的动画链:

- (void)viewWillAppear:(BOOL)animated;
- (void)viewDidAppear:(BOOL)animated;

关于iphone - 控制iOS6中MKMapView的动画速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12785529/

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