我遇到了问题,我找不到任何解决办法。
所以基本上,我有一个指南针,我想“弹出”/“弹出”到视图中,然后开始更新标题,但是在我解除/弹出指南针后标题停止更新。 / p>
喜欢:用户想要指南针 - >按下按钮 - >指南针弹出 - >开始旋转罗盘针 - >用户不再需要指南针/解散指南针 - >罗盘弹出视野。
所以我的问题是:如果我制作一个动画,另一个动画停止,我怎么能让它们相互运行?
在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];
}];
提前致谢。
答案 0 :(得分:1)
我假设您想要同时发生的两个动画是帧的旋转和移动?
最简单的方法是确保动画流畅,并遵循您的期望将指南针放在另一个视图中。
然后,您可以为指南针的框架设置动画。父母使指南针移入和移出并将旋转仅应用于指南针本身。
显示
[UIView animateWithDuration:1.f
animations:^{
compassContainer.center = CGPointMake(160, 410);
}];
轮换
// The code you already have changing the transform of directionsArrow
关闭
[UIView animateWithDuration:1.f
animations:^{
compassContainer.center = CGPointMake(160, 410);
} completion:^(BOOL finished) {
[locationManager stopUpdateHeading];
}];
答案 1 :(得分:1)
正如Paul.s在评论中提到的那样,这不是目前做动画的首选方式。而你用动画的块方法确实很容易。看看documentation,这是一个简短的例子。
-(IBAction)animateDelete:(id)sender
{
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseIn
animations:^{
// Your first animation here...
}
completion:^(BOOL finished) {
// Do some stuff
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Your second animation here...
}
completion:^(BOOL finished) {
// Do some stuff
}
];
}
];
}