我正在研究如何创建视图控制器的 NSMutableArray。
然后,一旦我有了那个数组,我怎么能在检测左右 UIgesture 滑动以动画进出视图的方法中使用它...
这是拾取我的手势的方法,它只是在两个视图之间制作动画,但是我想在视图控制器数组中的尽可能多的视图之间制作动画。
- (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)];
}];
}
}
作为一个方面,我有一个主视图控制器,我将这些视图控制器作为子视图加载...至少这是计划。我目前正在使用视图执行此操作...
http://dl.dropbox.com/u/53813770/SMPrototypeB.zip
更新:
这是一张图表,向你们展示了我想要达到的目标。
这是让它从数组中加载视图的代码。谢天谢地,真是痛苦。
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];