0

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)];
        }];

    }
}
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • Have you tried with UIScrollView? I personally find UIScrollView's effect better than swipe gesture. – nhahtdh May 31 '12 at 07:47
  • I need the viewControllers of each view because I am doing a bunch of other stuff (web requests etc) in each view that I want to control with the viewcontrollers... do you think this is a good idea? – HurkNburkS May 31 '12 at 08:09

1 Answers1

0

Sorry but you should use a UInavigationController to switch between views of view controller. You can stillanimate the frame and not use the classic animation included in uinavigation controlller. you push and pop view controller in the navigation controller. look for UINavigationController in the apple doc, you dont need to have the navigation bar at the top if that's what you're trying to avoid with your code.

Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81
  • Yep, the particular thing I am wanting to do here is inside a view thats inside a navigation controller... Its hard to explaine but basicly I have several views in the navigatoinstack, then the final view needs to display a ton more information than one view can handle, do I am going to have a swipable interface that the user can swipe back and forth to show all the relitive information just in a bunch of these views I am trying to make. – HurkNburkS May 31 '12 at 08:14
  • you can have navigation controller within navigation controller – Nicolas Manzini May 31 '12 at 12:13