2012-05-31 62 views
0

我已經創建了三個viewControllers的數組,我想在它們之間滑動。並在屏幕上進行動畫製作。使用NSMutableArray來更改子視圖

到目前爲止,我已經創建了視圖數組,並具有手勢控制,並將數組的第一個視圖加載到viewController的viewDidLoad方法中,該方法持有我的動畫內容。

我已經做了什麼添加到viewController對象,(當前,furutre)當應用程序第一次加載我把數組的第一個視圖到當前viewController ..然後當我刷新視圖我加載下一個視圖int他排列到未來的視圖控制器和執行一個動畫..然後,我對第三個動畫做同樣的事情,但它的分解,因爲我沒有將第二個視圖傳遞給當前,然後在最後一個動畫之前將第三個視圖傳遞給未來。 (希望這是有道理的。)

繼承人的代碼,這就是在做什麼,我到目前爲止做的..

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    self.title = @"Prototype"; 
    //Initalizse the swipe gestuer listener 
    [self setupLeftSwipeGestureRecognizer]; 
    [self setupRightSwipeGestureRecognizer]; 

    //Initalize all of the swipe views 
    DetailViewController *DVCA = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]]; 
    DetailViewControllerB *DVCB = [[DetailViewControllerB alloc] initWithNibName:@"DetailViewControllerB" bundle:[NSBundle mainBundle]]; 
    DetailViewControllerC *DVCC = [[DetailViewControllerC alloc] initWithNibName:@"DetailViewControllerC" bundle:[NSBundle mainBundle]]; 

    //Assinge swipeviews to viewArray 
    viewArray = [NSArray arrayWithObjects:DVCA, DVCB, DVCC, nil]; 

    //Initalize viewcount so it can keep track of which viewController is in view 
    viewCount = 0; 

    // set detail View as first view 
    currentViewController = [viewArray objectAtIndex:viewCount]; 
    [self.view addSubview:currentViewController.view]; 

} 


// Need to change this to work with viewArray 
- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture { 

    //Left swipe 
    if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) { 

     //stops swipes from returning any viewCount outside of viewArrays range 
     if ((viewCount >= 0) || (viewCount >= 2)) { 
      //Increment for next view 
      viewCount += 1; 

      futureViewController = [viewArray objectAtIndex:viewCount]; 
      [self.view addSubview:futureViewController.view]; 
      [futureViewController.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)]; 

      [UIView animateWithDuration:0.25 animations:^{ 
       [futureViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
       [currentViewController.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
      }]; 

     } 

    } 
    //Right swipe -- still need to do this (go back through the view array. 
    else if (gesture.direction == UISwipeGestureRecognizerDirectionRight){ 

     [UIView animateWithDuration:0.25 animations:^{ 
      [self.detailViewA.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
      [self.detailViewB.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     }]; 

    } 
} 
+0

你用UIScrollView試過嗎?我個人發現UIScrollView的效果比滑動手勢更好。 – nhahtdh

+0

我需要viewController的每個視圖,因爲我正在做一堆其他的東西(web請求等)在每個視圖中,我想控制viewcontrollers ...你認爲這是一個好主意? – HurkNburkS

回答

0

對不起b你應該使用UInavigationController在視圖控制器的視圖之間切換。 您可以對框架進行平滑處理,而不使用uinavigation控制器中包含的經典動畫。 您在導航控制器中按下並彈出視圖控制器。在apple文檔中尋找UINavigationController,如果這就是你想要避免的代碼,那麼你不需要在頂部有導航欄。

+0

是的,我想要在這裏做的特定事情是在一個導航控制器內的視圖內...它很難解釋,但基本上我有navigatoinstack中的幾個視圖,然後最後的視圖需要顯示更多的信息比噸一個視圖可以處理,我是否會有一個可以滑動的界面,用戶可以來回滑動顯示所有的可靠信息,只是我正在試圖創建一堆這些視圖。 – HurkNburkS

+0

您可以在導航控制器中安裝導航控制器 –