1

私はios開発の初心者です。プロジェクトでホイール イメージを使用しています。アニメーションはフォアグラウンド モードで正常に動作しています。その後、ホームボタンを押しました。アプリを再起動すると、ホイールアニメーションが機能しません。これは私のコードです:

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 1.0f;
animation.repeatCount = INFINITY;
[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
4

2 に答える 2

3

これを試して、

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addAnimation:) name:UIApplicationWillEnterForegroundNotification object:nil];

}

- (void)addAnimation:(NSNotification *)notificaiton
 {
 CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
 animation.fromValue = [NSNumber numberWithFloat: 2*M_PI];
 animation.toValue = [NSNumber numberWithFloat:0.0f];
 animation.duration = 4.0f;
 animation.repeatCount = INFINITY;
 [imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
 [imageRight.layer addAnimation:animation forKey:@"SpinAnimation"];
 }
//-----------------------------------------------------------------------------

//How to remove an observer for NSNotification

      [[NSNotificationCenter defaultCenter] removeObserver:self];
于 2013-06-17T14:05:21.983 に答える