8

我有一個應用程序,它有一箇中央視圖,兩個視圖關閉到它的每一側。我想要兩個導航欄按鈕,左側和右側,將新的導航控制器從左側或右側推到視圖上。iPhone向左推動視圖控制器

當您通過使用NavigationController的pushviewController:方法推新視圖來更改視圖時,視圖似乎從右側滑入。我如何改變這個從左邊滑入?

回答

8

而不是使用導航控制器,我只是移動視圖。

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]; 
+0

所以加載視圖控制器以正常方式,那麼得到在視圖上的把手,然後將它?我也必須手動更改導航欄按鈕以及 – 2009-07-08 04:31:25

+0

正確。正常加載視圖控制器,並將currentView移出屏幕並移入newView。 – 2009-07-08 05:08:38

4

我不認爲你可以明確定義UINavigationControllers中的滑動方向。您可能能夠做的是將當前視圖從導航堆棧中彈出以顯示之前的視圖,該視圖將以您想要的方式生成動畫。但是,如果您想要顯示不同的視圖控制器,則這可能很複雜,具體取決於您在當前視圖上執行的操作。

如果您的工作流程不太複雜,您可以在當前視圖控制器中保存對之前視圖控制器的引用。這取決於你對當前視圖什麼(如選擇一個表格視圖單元格),你可以改變你的前視圖控制器需要的任何數據,然後調用

[self.navigationController popViewController]; 

或任何正確的方法是(我認爲這很接近它)。這樣可以讓您使用所需的動畫向下移動導航堆棧,如果您的導航堆棧具有一定數量的視圖,則可以使用該動畫。

0

要獲得「尖尖」類型的按鈕,您需要使用不同的方法。

在你的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]; 
9

我已經做了改變動畫方向,當我們推視圖控制器。 您可以在這裏更改動畫類型[動畫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]; 
0

可以繼承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]; 

推進會由左到右,右彈出向左

3

什麼裏德·奧爾森說:您只需掛上一個按鈕,即可開始滑動至相同的方法,並添加一個跟蹤t的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]; 
} 
相關問題