我已經創建了三個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)];
}];
}
}
你用UIScrollView試過嗎?我個人發現UIScrollView的效果比滑動手勢更好。 – nhahtdh
我需要viewController的每個視圖,因爲我正在做一堆其他的東西(web請求等)在每個視圖中,我想控制viewcontrollers ...你認爲這是一個好主意? – HurkNburkS