アニメーション付きのモデル ビューを表示しています。デフォルトでは、下から上に表示されます。アニメーションを左から右に移動するにはどうすればよいですか? ナビゲーションコントローラーを使用できることはわかっています。しかし実際には、表示ビューにはナビゲーション バーは必要なく、モーダル表示ビューにもナビゲーション バーは必要ありません。それでも、左から右への移行が必要です。
6 に答える
次のコードを使用して、View Controller を表示しながら右から左にアニメーション化できます。
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentViewController:localitiesView animated:NO completion:nil];
は4つだけUIModalTransitionStyle
です。
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
あなたが言ったように、navコントローラーはそのようにプッシュします。それを使用したくない場合は、ビューを自分でアニメーション化する必要があります。
アニメーション中にモーダル ビューを表示するビューが表示されないため (代わりに、表示ビューがウィンドウの背景に置き換えられ、モーダル ビューがその上でアニメーション化される)、マシューのソリューションを実装する際に問題が発生しました。 . 代わりに、表示中の UIViewController のビューにモーダル ビューをサブビューとして追加し、アニメーション化しました。別のアニメーションがリクエストされたので、説明しているアニメーションを表すためにいくつかの値を変更しようとしましたが、実際には以下のコードをテストしていません。
UIViewController *modalView = //init your UIViewController
[modalView loadView];
CGRect finalFrame = modalView.view.frame;
[modalView.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:1.0 animations:^{
[self.navigationController setNavigationBarHidden:YES];
[self.view addSubview:modalView.view];
[modalView.view setFrame:finalFrame];
}];
お役に立てれば。
UINavigationController
にはnavigationBarHidden
プロパティがあります。これを YES に設定すると、ナビゲーション バーを表示しなくても、左から右へのトランジション スタイルやその他のナビゲーション コントローラーの機能を利用できます。
別のオプションを表示したかっただけです。これにより、UIViewアニメーションを使用して、ビューを上から下に表示できます。非表示の状態で新しいビューを追加する必要があることに注意してください。ビューが完全にロードされた状態でアニメーションが開始されるようにします。
AddViewController *controller = [[AddViewController alloc] initWithNibName:@"AddViewController" bundle:[NSBundle mainBundle]];
controller.blogs = self.blogs;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.toolbarHidden = YES;
navController.navigationBarHidden = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navController animated:NO];
navController.view.frame = CGRectMake(0, -480, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20);
navController.view.hidden = NO;
[UIView animateWithDuration:0.3
animations:^{
navController.view.frame = CGRectMake(0, 20, navController.view.frame.size.width, navController.view.frame.size.height);
}];
次のようなことを試すことができます:
UIViewController *fooViewController = [[[UIViewController alloc] init] autorelease];
CGSize theSize = CGSizeMake(320, 460);
fooViewController.view.frame = CGRectMake(0 - theSize.width, 0, theSize.width, theSize.height);
[UIView beginAnimations:@"animationID" context:NULL];
fooViewController.view.frame = CGRectMake(0, 0, 320, 460);
[UIView commitAnimations];