I am woundering how I could create an NSMutableArray of viewcontrollers.
Then once I had that array how could I use it in a method that detects left and right UIgesture swipes to animate in and out of view...
this is the method that is picking up my gestures which is just animating between two views, however I would like to animate between as many views that are in the array of view controllers.
- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture {
//Left swipe
if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) {
[UIView animateWithDuration:0.25 animations:^{
[self.detailViewB.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.detailViewA.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}
//Right swipe
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)];
}];
}
}
as a side I have a master view controller that I am loading these viewcontrollers into as subviews... well at least thats the plan.. Im currently doing this with the views...
http://dl.dropbox.com/u/53813770/SMPrototypeB.zip
UPDATED:
here is a graphic showing you guys what I am trying to achive.
Heres the code that got it to load the view from the array.. thank goodness, what a pain.
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]];
//Create Array of views
viewArray = [NSArray arrayWithObjects:DVCA, DVCB, DVCC, nil];
// set detail View as first view
UIViewController *recordController = [viewArray objectAtIndex:0];
// This was the bit causing me so many issues.
[self.view addSubview:recordController.view];
Looking at your project and seeing that your root view controller is in fact a navigation controller, I'm reposting as an answer.
If your initial view controller is a navigation controller, then the OS gives you the array you're looking for, it's the viewControllers property on UINavigationController. That's immutable but you could make a mutable copy of it.
Same way as you'd create any other array of objects:
Create the objects.
Put them in the array.
You certainly can do that in your app delegate or root view controller -- whichever object is in charge of all the other view controllers. I'd probably go with having the app delegate manage the view controllers. Then you can set the first responder as the target of the swipe gesture recognizer, and implement the action to switch between view controllers in the app delegate (which is part of the responder chain).
How about using an out of the box UIScrollView to get the same effect? It supports scrolling in multiple directions, would save you all the overhead of developing a new control, and you wouldn't have to worry about violating any HIG guidelines.