iphone - 多个动画相继出现

标签 iphone ios animation uiimageview mkmapview

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

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

例如:用户想要指南针 -> 按下按钮 -> 指南针弹出 -> 开始旋转指南针 -> 用户不再需要指南针/关闭指南针 -> 指南针从 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/

相关文章:

ios - 使用 IOS 8.3 的 Safari 上的 Angular ng-click 问题

iphone - 如何在 iPhone 上改变 View 时制作溶解动画?

ios - 如何在不使用浏览器的情况下使用 Sails.JS 打开 Web 套接字?

c++ - Xcode:与第 3 方框架链接和编译

c# - 在动画完成时删除 FrameworkElements

objective-c - 动画阿尔法变化

java - ObjectAnimator Android 在使用 API 19 的真实设备上无法正常工作

ios - 在 Swift 中根据条件使用调度队列的最佳方法

iphone - UITableView - 方法未被调用

ios - CIColorMatrix Filter 结果很奇怪