iPhone で View Controller を左方向に押す
-
11-09-2019 - |
質問
中央にビューがあり、その両側に 2 つのビューがあるアプリがあります。新しいナビゲーション コントローラーをビューの左側または右側から押す、左右 2 つのナビゲーション バー ボタンが必要です。
PushviewController を使用して新しいビューをプッシュしてビューを変更する場合:NavigationController のメソッドを使用すると、ビューが右からスライドして表示されます。これを左からスライドインするように変更するにはどうすればよいですか?
解決
の代わりにナビゲーションコントローラを使用するのでは、私はちょうどビューを移動します。
CGRect inFrame = [currentView frame];
CGRect outFrame = firstFrame;
outFrame.origin.x -= inFrame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[newView setFrame:inFrame];
currentView setFrame:outFrame];
[UIView commitAnimations];
他のヒント
私は、変更アニメーションの方向を行っています。 あなたはここでアニメーションの種類を変更することができますの [アニメーションsetSubtype:kCATransitionFromRight];
ViewController *elementController = [[ViewController alloc] init];
// set the element for the controller
ViewController.element = element;
// push the element view controller onto the navigation stack to display it
CATransition *animation = [CATransition animation];
[[self navigationController] pushViewController:elementController animated:NO];
[animation setDuration:0.45];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[elementController.view layer] addAnimation:animation forKey:@"SwitchToView1"];
[elementController release];
私はあなたが明示的UINavigationControllers方向にスライド定義することができるとは思いません。何をすることができるかもしれないと、あなたが望む方法でアニメーションしまう前にビューを表示するには、ナビゲーションスタックから現在のビューをポップです。あなたが別のビューコントローラを使用すると、現在のビューの上に何をすべきかに応じて、表示されるようにしたい場合は、これが複雑になることがあります。
あなたのワークフローが複雑すぎていない場合は、、あなたは現在のビューコントローラ内の前のビューコントローラへの参照を保持することができます。あなたが現在のビュー(のようなテーブルビューのセルを選択)に何をすべきかに応じて、あなたが前にビューコントローラに必要なデータをすべて変更し、
呼び出すことができます[self.navigationController popViewController];
または任意の正しい方法は、(私はそれがどのようにかなり近いと思う)です。それはあなたがあなたのNAVスタックがその上にビューのセット数を持っている場合に動作したいアニメーション、とNAVスタックを下に移動させます。
リード・オルセンが言った:あなたは、同じ方法までスライドを開始一つのボタンを、フックアップとビューが表示されているかどうかを追跡するBOOLを追加する必要があります。すべてを行う必要が適切に起源を設定されています。
- (IBAction)slideMenuView
{
CGRect inFrame = [self.view frame];
CGRect outFrame = self.view.frame;
if (self.viewisHidden) {
outFrame.origin.x += inFrame.size.width-50;
self.viewisHidden = NO;
} else {
outFrame.origin.x -= inFrame.size.width-50;
self.viewisHidden = YES;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.menuView setFrame:inFrame];
[self.view setFrame:outFrame];
[UIView commitAnimations];
}
「先のとがった」タイプのボタンを取得するには、別の方法を使用する必要があります。
あなたのAppDelegateでます:
UITableViewController *first = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
UITableViewController *second = [[SomeOtherViewController alloc] initWithStyle:UITableViewStylePlain];
NSArray *stack = [NSArray arrayWithObjects: first, second, nil];
UINavigationController *nav = [[UINavigationController alloc] init];
[nav setViewControllers:stack animated:NO];
RTLNavigationController:UINavigationController を継承して、これらの関数を上書きできます。
- (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
DummyViewController*dvc = [[DummyViewController alloc] init];
[super pushViewController:viewController animated:NO];
[super pushViewController:dvc animated:NO];
[dvc release];
[super popViewControllerAnimated:YES];
}
そして
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
UIViewController *firstViewController = [super popViewControllerAnimated:NO];
UIViewController *viewController = [super popViewControllerAnimated:NO];
[super pushViewController:viewController animated:animated];
return firstViewController;
}
そしてアプリケーションデリゲートでは次のようになります。
navCon = [[RTLNavigationController alloc] init];
rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
rootViewController.contextDelegate = self;
DummyViewController *dvc = [[DummyViewController alloc]init];
[navCon pushViewController:dvc animated:NO];
[dvc release];
[navCon pushViewController:rootViewController animated:NO];
[self.window addSubview:navCon.view];
プッシュは左から右、ポップは右から左になります。