gpt4 book ai didi

iphone - 多个动画相继出现

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:05 24 4
gpt4 key购买 nike

我遇到了一个问题,我找不到任何解决方案。

所以基本上,我有一个指南针,我想“弹出”/“弹出”到 View 中,然后开始更新航向,但在我关闭/弹出指南针后航向停止更新。

喜欢:用户想要指南针-> 按下按钮-> 指南针弹出-> 开始旋转指南针针-> 用户不再需要指南针/关闭指南针-> 指南针从视野中弹出。

所以我的问题是:如果我制作了一个动画,另一个动画停止了,我如何才能让两个动画相互追赶?

在 showCompass 中:

(IBAction) showCompass:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
directionsArrow.center = CGPointMake(160, 410);
[UIView commitAnimations];

在位置管理器中:

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];
}];

在位置管理器中:

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

提前致谢。

最佳答案

我假设您希望同时发生的两个动画是帧的旋转和移动?

要确保动画流畅并符合您的预期,最简单的方法是将指南针放在另一个 View 中。

然后,您可以为指南针的父级框架设置动画,使指南针移入和移出,并将旋转仅应用于指南针本身。

显示

[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];
}];

关于iphone - 多个动画相继出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13336594/

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