2

問題が発生しているので、解決策が見つかりません。

つまり、基本的に、ビューに「ポップイン」/「ポップアウト」してから見出しの更新を開始したいコンパスがありますが、コンパスを閉じたりポップアウトしたりすると、見出しの更新が停止します。

例:ユーザーがコンパスを望んでいる->ボタンを押す->コンパスがポップアップする->コンパスの針を回転させ始める->ユーザーはコンパスをもう必要としない/コンパスを閉じる->コンパスが見えなくなる。

だから私の質問は:私が1つのアニメーションを作成すると、他のアニメーションが停止しますが、どうすれば両方を互いに追いかけることができますか?

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

前もって感謝します。

4

2 に答える 2

1

同時に発生させたい2つのアニメーションは、フレームの回転と移動だと思いますか?

アニメーションがスムーズで期待どおりになるようにするための最も簡単な方法は、コンパスを別のビュー内に配置することです。

次に、コンパスの親のフレームをアニメートして、コンパスを内外に移動させ、コンパス自体だけに回転を適用できます。

見せる

[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];
                 }];
于 2012-11-11T23:43:20.383 に答える
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
                                          }
                          ];
                     }
    ];
}
于 2012-11-11T23:43:35.983 に答える