いくつかのセグメント化されたコントロールとスライダーを設定して、さまざまなトランジション アニメーションで遊ぶ簡単なアプリを作成しました。
(フリップ/カール)、(左/右) | (上/下)、(EaseInOut/EaseIn/EaseOut/Linear)
ビュー コントローラー クラスを作成しました。スーパー ビュー コントローラーは、サブ クラスの 2 つのインスタンスを切り替えます。
次の画像からわかるように、最初に 2 番目のインスタンスに切り替えると、アニメーションの発生中にセグメント化されたコントロールが破損します。彼らは自分自身を完全に描くのに十分な時間がなかったと思います.
http://img689.imageshack.us/img689/2320/mangledbuttonsduringtra.png
アニメーションが完了したら、それ以降は問題ありません。
で指定cache:NO
するsetAnimationTransition
と役立ちますが、セグメント化されたコントロールのテキストには、ある種のプログレッシブ リビールがまだあるようです。それらはまだ適切に事前レンダリングまたは初期化されていないようです.. (この場合、ビューは変更されておらず、キャッシュ可能である必要があるため、トランジション先のビューをキャッシュしている間にこれを行う方法は確かにあります。)
本のいくつかのチュートリアルに基づいてコードを作成しているのでdidReceiveMemoryWarning
、インスタンス化されたビュー コントローラーを nil に設定するように更新しました。シミュレーターでメモリ警告を呼び出すと、それが他のビューをパージしていると想定し、ロード後の最初の遷移のように動作し、遷移先のビューが上の画像のように表示されます。
コードを含めても問題ないと思います (スパム行為と見なされた場合は申し訳ありません) else
。 1位:
- (IBAction)switchViews:(id)sender
{
[UIView beginAnimations:@"Transition Animation" context:nil];
if (self.sideBViewController.view.superview == nil) // sideA is active, sideB is coming
{
if (self.sideBViewController == nil)
{
SideAViewController *sBController =
[[SideAViewController alloc] initWithNibName:@"SideAViewController" bundle:nil];
self.sideBViewController = sBController;
[sBController release];
}
[UIView setAnimationDuration:sideAViewController.transitionDurationSlider.value];
if ([sideAViewController.transitionAnimation selectedSegmentIndex] == 0)
{
// flip: 0 == left, 1 == right
if ([sideAViewController.flipDirection selectedSegmentIndex] == 0)
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view
cache:YES];
else
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view
cache:YES];
}
else
{
// curl: 0 == up, 1 == down
if ([sideAViewController.curlDirection selectedSegmentIndex] == 0)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view
cache:YES];
else
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view
cache:YES];
}
if ([sideAViewController.animationCurve selectedSegmentIndex] == 0)
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 1)
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 2)
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 3)
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[sideBViewController viewWillAppear:YES];
[sideAViewController viewWillDisappear:YES];
[sideAViewController.view removeFromSuperview];
[self.view insertSubview:sideBViewController.view atIndex:0];
[sideBViewController viewDidAppear:YES];
[sideAViewController viewDidDisappear:YES];
}