Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用NSMutableArray更改子视图_Iphone_Ios_Nsmutablearray_Uiswipegesturerecognizer - Fatal编程技术网

Iphone 使用NSMutableArray更改子视图

Iphone 使用NSMutableArray更改子视图,iphone,ios,nsmutablearray,uiswipegesturerecognizer,Iphone,Ios,Nsmutablearray,Uiswipegesturerecognizer,我已经创建了一个包含三个ViewController的数组,我想在它们之间滑动。并在屏幕上设置动画 到目前为止,我已经创建了视图数组,具有手势控制,并且正在将数组的第一个视图加载到保存动画内容的viewController的viewDidLoad方法中的视图中 我所做的是添加到viewController对象(当前、furutre),当应用程序首次加载时,我将阵列的第一个视图放入当前viewController。。然后,当我滑动视图时,我将阵列中的下一个视图加载到未来的viewcontrolle

我已经创建了一个包含三个ViewController的数组,我想在它们之间滑动。并在屏幕上设置动画

到目前为止,我已经创建了视图数组,具有手势控制,并且正在将数组的第一个视图加载到保存动画内容的viewController的viewDidLoad方法中的视图中

我所做的是添加到viewController对象(当前、furutre),当应用程序首次加载时,我将阵列的第一个视图放入当前viewController。。然后,当我滑动视图时,我将阵列中的下一个视图加载到未来的viewcontroller中,并执行动画。。然后我对第三个动画也做了同样的操作。。但是它崩溃了,因为在最后一个动画之前,我没有将第二个视图传递给当前,然后将第三个视图传递给未来。。(希望这有意义。)

这是我目前正在做的事情的代码

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

    }
}

很抱歉,您应该使用UInavigationController在视图控制器的视图之间切换。 您仍然可以设置帧的动画,而不使用uinavigation Controller中包含的经典动画。
您可以在导航控制器中按下并弹出视图控制器。在apple文档中查找UINavigationController,如果您的代码试图避免出现这种情况,您不需要在顶部设置导航栏。

您使用过UIScrollView吗?我个人觉得UIScrollView的效果比滑动手势更好。我需要每个视图的ViewController,因为我在每个视图中都做了一些其他事情(web请求等),我想用ViewController控制这些事情。。。你认为这是个好主意吗?是的,我想在这里做的特别的事情是在导航控制器内的视图中。。。很难解释,但基本上我在NavigationStack中有几个视图,然后最终视图需要显示比一个视图可以处理的信息多得多的信息,我是否要有一个可滑动的界面,用户可以来回滑动,以显示我试图创建的一组视图中的所有相关信息。您可以在导航控制器中设置导航控制器