RSS
 

メソッドの実行、遅延実行、キャンセル

10 3月
この記事を読むのに必要な時間の目安: 2

iPhone アプリ開発でアニメーションを入れる時などには、メソッドの実行、遅延実行、実行のキャンセルを使います。

// 例えば
- (void)viewDidLoad {
  [super viewDidLoad];

  // アニメーション1を実行
  [self performSelector:@selector(animation1) withObject:nil];
  // アニメーション2を10秒後に実行
  [self performSelector:@selector(animation2) withObject:nil afterDelay:10];
  // アニメーション3の実行をキャンセル
  [NSObject cancelPreviousPerformRequestsWithTarget:self
	 selector:@selector(animation3)
	 object:nil];
}

- (void)animation1 {
  // アニメーション1(略)
}

(略)

アニメーションの場合、スキップしたり、ボタンを押した時に処理を変えたい場合などでは実行キャンセルを使うと柔軟に記述できますね。

人気の記事

関連記事

 
No Comments

Posted in iPhone

 

Leave a Reply