Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
Ios UIView&;UIViewController应用程序设计_Ios_Ipad_Uiview_Xamarin.ios - Fatal编程技术网

Ios UIView&;UIViewController应用程序设计

Ios UIView&;UIViewController应用程序设计,ios,ipad,uiview,xamarin.ios,Ios,Ipad,Uiview,Xamarin.ios,我正在尝试让我的头周围的视图控制器,子视图控制器,视图,容器等。我正在做一个简单的应用程序,将有一组图标下来的左手边,当点击将打开一个不同的屏幕在右手边。基本设计是: 菜单栏将始终位于左侧,内容位于蓝色框中。我说的我应该具有以下结构是否正确: 然后,当按下左侧UIView上的图像时,我应该将新UIView推到右侧?或者这些应该是UIViewController?集装箱是从哪里来的 是否可以通过情节串连板执行此操作,或者不可能链接按钮以将新UIView推送到屏幕的不同部分,因此我需要通过代码执

我正在尝试让我的头周围的视图控制器,子视图控制器,视图,容器等。我正在做一个简单的应用程序,将有一组图标下来的左手边,当点击将打开一个不同的屏幕在右手边。基本设计是:

菜单栏将始终位于左侧,内容位于蓝色框中。我说的我应该具有以下结构是否正确:

然后,当按下左侧UIView上的图像时,我应该将新UIView推到右侧?或者这些应该是UIViewController?集装箱是从哪里来的


是否可以通过情节串连板执行此操作,或者不可能链接按钮以将新UIView推送到屏幕的不同部分,因此我需要通过代码执行此操作?

我建议使用容器视图控制器作为布局的根,然后在左侧菜单中使用子视图控制器,以及当前所选项目/选项卡的另一个视图控制器。 然后,选择后,只需交换右侧的(子)视图控制器(即,从父视图控制器中删除当前视图控制器并添加新的视图控制器)。
虽然一开始听起来可能有点复杂,但当你继续你的项目时,它更健壮,更容易实现更复杂的场景。

我建议使用容器视图控制器作为布局的根,然后在左侧菜单中使用子视图控制器,以及当前所选项目/选项卡的另一个视图控制器。 然后,选择后,只需交换右侧的(子)视图控制器(即,从父视图控制器中删除当前视图控制器并添加新的视图控制器)。
虽然一开始听起来可能有点复杂,但当你继续你的项目时,它更健壮,更容易实现更复杂的场景。

我建议使用容器视图控制器作为布局的根,然后在左侧菜单中使用子视图控制器,以及当前所选项目/选项卡的另一个视图控制器。 然后,选择后,只需交换右侧的(子)视图控制器(即,从父视图控制器中删除当前视图控制器并添加新的视图控制器)。
虽然一开始听起来可能有点复杂,但当你继续你的项目时,它更健壮,更容易实现更复杂的场景。

我建议使用容器视图控制器作为布局的根,然后在左侧菜单中使用子视图控制器,以及当前所选项目/选项卡的另一个视图控制器。 然后,选择后,只需交换右侧的(子)视图控制器(即,从父视图控制器中删除当前视图控制器并添加新的视图控制器)。
虽然第一次听上去可能有点复杂,但当您继续项目时,它更健壮,更容易实现更复杂的场景。

一个选项是使用
UISplitViewController
运行,它为您提供了大部分功能。但我会这样做

  • 有一个HomeViewController作为基本控制层。此类将处理:

    1.1左侧按钮的用户界面

    1.2控制按下左按钮时发生的情况

    1.3关闭右侧的子视图控制器

  • 左侧有一个
    UIView
    称之为navView或其他东西,右侧有另一个
    UIView
    称为containerView

    2.1导航视图始终可见

    2.2 containerView负责显示您的
    childViewController
    视图

  • 每当按下左侧的按钮时,您都会删除当前的childViewController并添加一个新的


  • 编辑**

    针对评论:


    初始化选项卡栏时,它会保留一个ViewController数组。因此,您的权利,viewDidLoad只调用一次。要实现这一点,您所要做的就是保留一个包含所有ViewController的数组,并从中切换它们。如果您愿意,我可以在此发布代码,对于最初的问题来说,这似乎有点过头了

    以下是我如何做到这一点的示例:

    - (void)updateChildViewController {
    
        //This is the VC that was being shown, but will be replaced by the new currentlyVisisbleViewController, we keep track of it so in the transitionFromViewController: method we have viewController to switch from.
        UIViewController *previousVisibleViewController = self.currentlyVisibleViewController;
    
        //We keep and array of both view controllers so that we only have to load them into memory once, so their viewDidLoad is only called once.
        if (!viewControllers) {
            viewControllers = [[NSMutableArray alloc] initWithObjects:[NSNull null], [NSNull null], nil];
        }
    
        //If a given VC has not been loaded before we know becuase it's spot in the viewControllers array will be Null. (as seen in the line above)
        if ([viewControllers objectAtIndex:self.displayType] == [NSNull null]) {
    
            id newlyLoadedViewController;
    
            //I have two display types I switch between, a map and list
            if (self.displayType == DTMap) {
                newlyLoadedViewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
            }
            else if (self.displayType == DTList) {
                newlyLoadedViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
    
            }
    
            //Set the object in it's location in viewControllers array
            [viewControllers setObject:newlyLoadedViewController atIndexedSubscript:self.displayType];
        }
    
        //Set the new currentlyVisibleViewController
        self.currentlyVisibleViewController = [viewControllers objectAtIndex:self.displayType];
    
        //Adjust the frame to fit in the contentView (or the "container" view)
        self.currentlyVisibleViewController.view.frame = self.contentView.frame;
    
        //Make sure that it resizes on rotation automatically along with the contentView.
        self.currentlyVisibleViewController.view.autoresizingMask = self.contentView.autoresizingMask;
    
        //Let the old VC know that is going to be removed if it exist. We lazy load the UIViewControllers so on intial launch, there is only one UIViewController loaded, once we switch to another one we will have a previousVisibleViewController.
        if (previousVisibleViewController) {
            [previousVisibleViewController willMoveToParentViewController:nil];
        }
    
        //Add the currentlyVisibleViewController as a childViewController
        [self addChildViewController:self.currentlyVisibleViewController];
    
        //If there was a previousVC then we animate between them
        if (previousVisibleViewController) {
            [self transitionFromViewController:previousVisibleViewController
                              toViewController:self.currentlyVisibleViewController
                                      duration:0.0f
                                       options:UIViewAnimationOptionTransitionNone
                                    animations:^{}
                                    completion:^(BOOL finished) {
    
                                        //Notify the new visible viewController than the move is done
                                        [self.currentlyVisibleViewController didMoveToParentViewController:self];
    
                                        //Tell the old one it is no longer on the screen and has been removed.
                                        [previousVisibleViewController removeFromParentViewController];
                                    }];
        }
    
        //Otherwise it's the first time we are adding a child so we need to link the views
        else {
    
            //Add it to content view, calls willMoveToParentViewController for us. We only have to set this once.
            [self.contentView addSubview:self.currentlyVisibleViewController.view];
        }
    
    }
    

    一个选项是使用
    UISplitViewController
    运行,它可以为您完成大部分工作。但我会这样做

  • 有一个HomeViewController作为基本控制层。此类将处理:

    1.1左侧按钮的用户界面

    1.2控制按下左按钮时发生的情况

    1.3关闭右侧的子视图控制器

  • 左侧有一个
    UIView
    称之为navView或其他东西,右侧有另一个
    UIView
    称为containerView

    2.1导航视图始终可见

    2.2 containerView负责显示您的
    childViewController
    视图

  • 每当按下左侧的按钮时,您都会删除当前的childViewController并添加一个新的


  • 编辑**

    针对评论:


    初始化选项卡栏时,它会保留一个ViewController数组。因此,您的权利,viewDidLoad只调用一次。要实现这一点,您所要做的就是保留一个包含所有ViewController的数组,并从中切换它们。如果您愿意,我可以在此发布代码,对于最初的问题来说,这似乎有点过头了

    以下是我如何做到这一点的示例:

    - (void)updateChildViewController {
    
        //This is the VC that was being shown, but will be replaced by the new currentlyVisisbleViewController, we keep track of it so in the transitionFromViewController: method we have viewController to switch from.
        UIViewController *previousVisibleViewController = self.currentlyVisibleViewController;
    
        //We keep and array of both view controllers so that we only have to load them into memory once, so their viewDidLoad is only called once.
        if (!viewControllers) {
            viewControllers = [[NSMutableArray alloc] initWithObjects:[NSNull null], [NSNull null], nil];
        }
    
        //If a given VC has not been loaded before we know becuase it's spot in the viewControllers array will be Null. (as seen in the line above)
        if ([viewControllers objectAtIndex:self.displayType] == [NSNull null]) {
    
            id newlyLoadedViewController;
    
            //I have two display types I switch between, a map and list
            if (self.displayType == DTMap) {
                newlyLoadedViewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
            }
            else if (self.displayType == DTList) {
                newlyLoadedViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
    
            }
    
            //Set the object in it's location in viewControllers array
            [viewControllers setObject:newlyLoadedViewController atIndexedSubscript:self.displayType];
        }
    
        //Set the new currentlyVisibleViewController
        self.currentlyVisibleViewController = [viewControllers objectAtIndex:self.displayType];
    
        //Adjust the frame to fit in the contentView (or the "container" view)
        self.currentlyVisibleViewController.view.frame = self.contentView.frame;
    
        //Make sure that it resizes on rotation automatically along with the contentView.
        self.currentlyVisibleViewController.view.autoresizingMask = self.contentView.autoresizingMask;
    
        //Let the old VC know that is going to be removed if it exist. We lazy load the UIViewControllers so on intial launch, there is only one UIViewController loaded, once we switch to another one we will have a previousVisibleViewController.
        if (previousVisibleViewController) {
            [previousVisibleViewController willMoveToParentViewController:nil];
        }
    
        //Add the currentlyVisibleViewController as a childViewController
        [self addChildViewController:self.currentlyVisibleViewController];
    
        //If there was a previousVC then we animate between them
        if (previousVisibleViewController) {
            [self transitionFromViewController:previousVisibleViewController
                              toViewController:self.currentlyVisibleViewController
                                      duration:0.0f
                                       options:UIViewAnimationOptionTransitionNone
                                    animations:^{}
                                    completion:^(BOOL finished) {
    
                                        //Notify the new visible viewController than the move is done
                                        [self.currentlyVisibleViewController didMoveToParentViewController:self];
    
                                        //Tell the old one it is no longer on the screen and has been removed.
                                        [previousVisibleViewController removeFromParentViewController];
                                    }];
        }
    
        //Otherwise it's the first time we are adding a child so we need to link the views
        else {
    
            //Add it to content view, calls willMoveToParentViewController for us. We only have to set this once.
            [self.contentView addSubview:self.currentlyVisibleViewController.view];
        }
    
    }
    

    一个选项是使用
    UISplitViewController
    运行,它可以为您完成大部分工作。但我会这样做

  • 有一个HomeViewController作为基本控制层。此类将处理:

    1.1左侧按钮的用户界面

    1.2控制按下左按钮时发生的情况

    1.3关闭右侧的子视图控制器