I have creates an array of three viewControllers which I would like to swipe between. and have animate across the screen.
So far I have created the array of views, have gesture control and am loading the first view of the array to the view in the viewDidLoad method of the viewController thats holding my animation stuff.
What I have done is added to viewController objects, (current, furutre) when the app first loads I put the first view of the array into the current viewController.. then when I swipe the view I Load the next view int he array into the future viewcontroller and perform an animation.. Then I do the same for the third animation.. however its breaking down, because I am not passing the second view to current then the third view to future before the last animation.. (hope this makes sense.)
Heres the code thats doing what I am doing so far..
- (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)];
}];
}
}