- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在创建一个应用程序,我必须在其中打开一个 View Controller 内的 2-3 个 View Controller ,因为我想为这些 View Controller 共享相同的滑动抽屉和导航栏。我关注了this教程。
我在 MainController 中使用了 ContainerView 并正确添加了子 Controller ,但我很难调整子 Controller 的大小以匹配 containerview
self.mainContainer.addSubview(vc.view)
self.mainContainer.translatesAutoresizingMaskIntoConstraints = false
addChildViewController(vc)
NSLayoutConstraint.activate([
vc.view.leadingAnchor.constraint(equalTo:mainContainer.leadingAnchor),
vc.view.trailingAnchor.constraint(equalTo: mainContainer.trailingAnchor),
vc.view.topAnchor.constraint(equalTo: mainContainer.topAnchor),
vc.view.bottomAnchor.constraint(equalTo: mainContainer.bottomAnchor)
])
vc.didMove(toParentViewController: self)
我收到以下错误
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x170095c70 h=-&- v=-&- UIView:0x127e17630.midY == UIView:0x127e15070.midY + 32 (active)>",
"<NSLayoutConstraint:0x1740970c0 V:|-(0)-[UIView:0x127e17630] (active, names: '|':UIView:0x127e15070 )>",
"<NSLayoutConstraint:0x174097020 UIView:0x127e17630.bottom == UIView:0x127e15070.bottom (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174097020 UIView:0x127e17630.bottom == UIView:0x127e15070.bottom (active)>
我认为 self.mainContainer.translatesAutoresizingMaskIntoConstraints = false 不知何故不起作用 subview Controller 未正确调整大小,因为在主 Controller 中,导航栏约为 64,并且相同高度的部分在 subview Controller 中从底部被剪裁。
MainController的元素约束
导航栏 left=top=right = 0, height = 64
UIContainerView left=right=bottom=0 and top to navbar = 0
最佳答案
您可以简单地设置vc
的框架,而不是将约束应用于vc 的
view
,即
vc.view.frame = self.containerView.bounds //Here
self.containerView.addSubview(vc.view)
self.addChildViewController(vc)
vc.didMove(toParentViewController: self)
关于ios - 在 UIContainerView swift ios 中调整 subview Controller 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45627451/
是否可以在 containerView 中放置一个 containerView?如果是这样,对该模型有什么影响吗?我的应用程序中有一个侧边菜单,所以我以经典方式使用 containerView。问题是
我正在努力将我的数据从一个 UIContainerView 获取到另一个 UIContainerView。例如:我有 2 个容器,分别是 calculatorContainer 和 displayRe
我是一名 iOS 开发新手,需要您的帮助。 我有一个简单的应用程序,由: 1个包含的 View Controller 3 个 UIContainerView,每个都链接到自己的 View Contro
我刚刚开始使用 Swift 2 编写我的应用程序,并避免使用 XIB 和 Storyboard。 但是,我无法复制 following feature .这正是我想要的。 我尝试创建一个 UIView
我有一个标准的扩展 UIViewController(称为 ParentViewController 或 PVC),并且想要一个由 ChildViewController 或 CVC 驱动的容器或 s
我一直在网上和苹果的文档中进行挖掘,但我似乎无法确定使用 UIContainerView 需要什么 iOS 版本。我有点沮丧,因为我没有掌握这些信息...... 最佳答案 UIContainerVie
我似乎无法正确推理这个问题,所以我希望有人能给我一些提示来指导我。 所以我在一个 UIScrollView 中有 4 个 UIContainerView。 当用户滑动时,容器显示 4 个单独的 UIV
我有两个 ContainerView,它们放置在彼此之上,例如 ContainerA 位于 ContainerB 的前面。 当按钮点击 ContainerA 的宽度和高度应更改为较小的尺寸时,将显示
所以我的 UIViewcontroller 中有一个静态的上部部分,所以我制作了 Container View ,它有一个带有两个单元格的静态表格 View 现在我希望当我单击一个单元格时,它会显示同
我有一个自定义类(我从 SO 获得)来迭代 UIView 的所有和每个子类。我没有得到的是我无法添加代码来免除 UIContainerView。 代码(在UIView+Recursion.m中): -
我正在以编程方式创建容器 View 。但是,我无法改变它的高度。我正在以编程方式设置它,但没有任何效果。 let supportView: UIView = UIView() let containe
我到处寻找解决方案,但一无所获。我有两个 View Controller ,我想将数据从 viewController.swift 传递到 resultViewController.swift(容器
我有一个父 View ,里面有一个容器 View 。当我设置父 View 背景颜色时,容器 View 不再显示 我尝试以编程方式设置两个 View 的背景颜色并将 alpha 值显式设置为 1,但没有
UIContainerView 显示一个 View Controller : 现在,当用户使用此代码点击全屏按钮时,我想使其全屏显示: @IBAction func fullscreen(_ send
我正在尝试创建一个使用 UIContainerView 来托管 UIViewController 的动态 View 流。 UIContainerView(或 UIViewController)需要以编
我在 UITableView 中显示数据时遇到问题。我尝试过以几种不同的方式实现我的需求,但所有这些方式似乎都会产生相同的结果。这是我尝试将内容容纳在 UIContainerView 中的最新尝试..
我正在努力在 UIContainerView 中嵌入一个 UIScrollView,这样我就可以拥有多个文本字段。 我尝试通过这个 SO answer 实现解决方案,但一直没有成功。 两个 View
我试图在我的应用程序页面上显示一个 UIContainerView 作为商店。这可以在这里看到: 作用在它上面的约束是Horizontally in container和Vertically in
我有一个 UIViewController,里面有一个 UIContainerView。基于某个条件是否为真,我想以编程方式将容器 View 的嵌入式 View 设置为不同的 UIViewContro
我在 Storyboard中添加了一个 UIScrollView,引用如下: @IBOutlet weak private var myScrollView: UIScrollView! 我想添加一个
我是一名优秀的程序员,十分优秀!