我很讨厌如何创建一个NSMutableArray的viewcontrollers。
然后,一旦有了该数组,如何在检测左右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];
最佳答案
查看您的项目,发现您的根视图控制器实际上是一个导航控制器,我将其发布为答案。
如果您的初始视图控制器是导航控制器,则操作系统会为您提供您要查找的数组,它是UINavigationController上的viewControllers属性。这是一成不变的,但您可以对其进行可变的复制。