【发布时间】:2012-10-31 10:57:17
【问题描述】:
我遇到了一个问题,我找不到任何解决方案。
所以基本上,我有一个罗盘,我想“弹出”/“弹出”到视图中,然后开始更新航向,但在我关闭/弹出罗盘后航向停止更新。
喜欢:用户想要指南针-> 按下按钮-> 指南针弹出-> 开始旋转指南针针-> 用户不再想要指南针/关闭指南针-> 指南针弹出视图。
所以我的问题是:如果我制作了一个动画,另一个动画停止了,我如何让两者能够相互运行?
在showCompass中:
(IBAction) showCompass:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
directionsArrow.center = CGPointMake(160, 410);
[UIView commitAnimations];
在 locationManager 中:
float oldRadian = (-manager.heading.trueHeading * M_PI/180.0f);
float newRadian = (-newHeading.trueHeading * M_PI/180.0f);
CABasicAnimation *animation;
animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:oldRadian];
animation.toValue = [NSNumber numberWithFloat:newRadian];
animation.duration = 0.5f;
[directionsArrow.layer addAnimation:animation forKey:@"animateMyRotation"];
directionsArrow.transform = CGAffineTransformMakeRotation(newRadian);
在dismissCompass中:
-(IBAction) dismissCompass {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
directionsArrow.center = CGPointMake(160, 410);
[UIView commitAnimations];
[locationManager stopUpdateHeading];
}
新代码: *显示:*
[UIView animateWithDuration:1.f
animations:^{
compassDial.center = CGPointMake(160, 504-92);
pushView.center = CGPointMake(160, 500-92);
//directionsArrow.center = CGPointMake(160, 502-92);
} completion:^(BOOL finished) {
directionsArrow.hidden = NO;
[locationManager startUpdatingHeading];
}];
在 locationManager 中:
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
float oldRadian = (-manager.heading.trueHeading * M_PI/180.0f);
float newRadian = (-newHeading.trueHeading * M_PI/180.0f);
CABasicAnimation *animation;
animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:oldRadian];
animation.toValue = [NSNumber numberWithFloat:newRadian];
animation.duration = 0.5f;
[directionsArrow.layer addAnimation:animation forKey:@"animateMyRotation"];
directionsArrow.transform = CGAffineTransformMakeRotation(newRadian);
解雇:
[UIView animateWithDuration:1.f
animations:^{
compassDial.center = CGPointMake(160, 700);
directionsArrow.center = CGPointMake(160, 700);
} completion:^(BOOL finished) {
[locationManager stopUpdatingHeading];
}];
提前致谢。
【问题讨论】:
-
您可能想在动画完成后调用
[locationManager stopUpdateHeading];... 还谈到用于动画的语法 - “在 iOS 4.0 及更高版本中不鼓励使用此方法。您应该使用使用基于块的动画方法来指定您的动画。” -
有什么问题?您发表了一堆声明并发布了一些代码,但从未说出实际问题是什么。
-
问题是:如果我制作一个动画,另一个动画停止,我怎样才能让两个动画相互运行?
标签: iphone ios animation uiimageview mkmapview