什么是用X code中的自动布局来开发应用程序的最佳方式? [英] What is the best way to develop applications using the auto layout in Xcode?
问题描述
所以我想这是要被关闭了太主观,太舆论基础,但如果有人能帮助我,我将AP preciate它。
So I guess this is going to be closed for being too subjective and too opinion based but if anyone can help me I would appreciate it.
我有一个问题。如果我有几个控制器,都差不多例如,它们具有相同的背景一样的东西,有一个菜单绕来绕去的边缘,但实际内容是不同的。我有一对夫妇的想法。 1)只要有一个视图控制器,如果用户选择菜单上的其他选项只是杀了对于当前视图中的对象和产卵该菜单中的新对象。我对这样的问题是,我无法找到一种方法,使用这种自动布局。
I got a question. If I have a few controllers that all have almost the same thing For example they have the same background, have a menu going around the edge but the actual content is different. I had a couple of ideas. 1) Just have one view controller and just kill the objects for that current view if the user chooses a different option on the menu and spawn the new objects for that menu. My issue with this way was that I could't find a way to use the auto layout with this.
第二个办法就是要在一个.swift文件中的函数,我可以打电话,并创建一个图像视图并设置菜单那样的一切。我这里有相反的问题,但现在自动布局将无法工作。
Second way would to be have a function in a .swift file that I can call and it creates an image view and sets up the menu an everything like that. I have the opposite issue here though, now the auto layout won't work.
应用程序开发者必须有这样的一种方式,我只是大概这种思维完全走错了路。
App devs must have a way of doing this, I'm just probably thinking of this completely the wrong way.
有没有更好的方式来这样做 - 我相信有?我想AP preciate,如果有人可以点我正确的方向。
Is there a better way to be doing this - I am sure there is? I would appreciate it if someone could point me in the correct direction.
感谢
编辑:
我要清楚,我使用的语言是迅速的。
I should make it clear that the language I am using is swift.
推荐答案
您可以创建自定义的容器视图控制器并交换看法控制器,用于根据用户选择了改变的部分。
You can create custom container view controller and swap the view controllers for the part that change according to the user selection.
- 添加示例 -
--Adding Example--
例如iPad的设置应用。左边是一个表视图,右侧是用户选择改变细节视图。所以泰伯维可以在视图控制器被包裹让我们说ListViewController。这不会改变。右侧将DetailViewController这将根据用户的选择来交换。您ContainerViewController将在任何时候都2视图控制器。
e.g iPad's Settings app. The left side is a table view and right side is detail view which changes on user selection. So Tableview can be wrapped in a view controller let's say ListViewController. This will not change. The right side will be DetailViewController which would be swapped according to user selection. Your ContainerViewController will have 2 view controllers at all times.
下面是如何视图控制器添加为子,并设置自己的观点在Objective-C。
Here is how to add view controllers as child and set their views in objective-c.
- (void) setupContentViewControllerWith: (DetailViewController*) detailViewController andListViewController:(ListViewController*)listViewController {
[self addChildViewController:listViewController];
[self addChildViewController:detailViewController];
listViewController.view.frame = CGRectMake(kListView_X, kListView_Y, kListView_Width, kListView_Height);
detailViewController.view.frame = CGRectMake(kListView_Width, kDetailView_Y, self.view.bounds.size.width, self.view.bounds.size.height-kDetailView_Y);
[self.scrollContainer addSubview:listViewController.view];
[self.scrollContainer addSubview:detailViewController.view];
[self.scrollContainer setContentSize:CGSizeMake(kListView_Width+self.view.bounds.size.width, self.view.bounds.size.height)];
}
当用户从列表中选择新的项目,你可以交换DetailViewControllers如下
When user selects new item from the list, you can swap DetailViewControllers as below
- (void) replaceEpisodeControllerWith:(DetailViewController *)detailViewController {
detailViewController.view.frame = CGRectMake(kListView_Width, kDetailView_Y, self.view.bounds.size.width, self.view.bounds.size.height-kDetailView_Y);
[UIView transitionFromView:currentDetailViewController.view
toView:detailViewController.view
duration:0.0
options:UIViewAnimationOptionTransitionNone
completion:^(BOOL finished)
{
[currentDetailViewController.view removeFromSuperview];
[currentDetailViewController removeFromParentViewController];
[currentDetailViewController release];
currentDetailViewController = detailViewController;
}];
}
我没有这个迅速版本。
I don't have swift version of this.
这篇关于什么是用X code中的自动布局来开发应用程序的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!