本文介绍了视图控制器的 NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在纠结如何创建一个 NSMutableArray 的视图控制器.

I am woundering how I could create an NSMutableArray of viewcontrollers.

然后一旦我有了那个数组,我怎么能在检测左右 UIgesture 滑动的方法中使用它来动画进出视图...

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

更新:

这是一张图表,向你们展示了我正在努力实现的目标.

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

推荐答案

如何使用开箱即用的 UIScrollView 来获得相同的效果?它支持在多个方向上滚动,可以为您节省开发新控件的所有开销,而且您不必担心违反任何 HIG 准则.

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.

这篇关于视图控制器的 NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 11:59