Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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 分页滚动视图约束布局问题_Ios_Swift_Uiscrollview_Constraints - Fatal编程技术网

Ios 分页滚动视图约束布局问题

Ios 分页滚动视图约束布局问题,ios,swift,uiscrollview,constraints,Ios,Swift,Uiscrollview,Constraints,在这个项目中,我基于约束创建了分页滚动视图。大多数视图都是在xib中设置的(SlideViewController.和UIView的SlideView子类将添加到滚动视图)。SlideViewController包含UIScrollView和UIView作为内容视图,内容视图绑定到带有约束的滚动视图。在xib中,这是一个简单的设置。 当我尝试将多个SlideView添加到内容视图时,问题出现了。当然,我想添加约束。首先,它抛出警告无法同时满足约束。详细信息: "<NSLayoutConst

在这个项目中,我基于约束创建了分页滚动视图。大多数视图都是在xib中设置的(SlideViewController.和UIView的SlideView子类将添加到滚动视图)。SlideViewController包含UIScrollView和UIView作为内容视图,内容视图绑定到带有约束的滚动视图。在xib中,这是一个简单的设置。 当我尝试将多个SlideView添加到内容视图时,问题出现了。当然,我想添加约束。首先,它抛出警告
无法同时满足约束。
详细信息:

"<NSLayoutConstraint:0x600001806b70 H:|-(0)-[UIView:0x7ffac0d0cb40]   (active, names: '|':UIScrollView:0x7ffac1842600 )>",
    "<NSLayoutConstraint:0x600001806d00 UIView:0x7ffac0d0cb40.centerX == UIScrollView:0x7ffac1842600.centerX   (active)>",
    "<NSLayoutConstraint:0x600001805400 UIScrollView:0x7ffac1842600.trailing == UILayoutGuide:0x6000002308c0'UIViewSafeAreaLayoutGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x6000018058b0 UIScrollView:0x7ffac1842600.leading == UILayoutGuide:0x6000002308c0'UIViewSafeAreaLayoutGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000018065d0 H:|-(0)-[PagingScrollView.SlideView:0x7ffac380be10](LTR)   (active, names: '|':UIView:0x7ffac0d0cb40 )>",
    "<NSLayoutConstraint:0x600001806670 PagingScrollView.SlideView:0x7ffac380be10.width == UIScrollView:0x7ffac1842600.width   (active)>",
    "<NSLayoutConstraint:0x600001806760 H:[PagingScrollView.SlideView:0x7ffac380be10]-(0)-[PagingScrollView.SlideView:0x7ffac3814d10](LTR)   (active)>",
    "<NSLayoutConstraint:0x600001806ad0 PagingScrollView.SlideView:0x7ffac3814d10.width == UIScrollView:0x7ffac1842600.width   (active)>",
    "<NSLayoutConstraint:0x600001806d50 H:[PagingScrollView.SlideView:0x7ffac3814d10]-(0)-[PagingScrollView.SlideView:0x7ffac3805d20](LTR)   (active)>",
    "<NSLayoutConstraint:0x600001806e90 PagingScrollView.SlideView:0x7ffac3805d20.width == UIScrollView:0x7ffac1842600.width   (active)>",
    "<NSLayoutConstraint:0x6000018070c0 H:[PagingScrollView.SlideView:0x7ffac3805d20]-(0)-[PagingScrollView.SlideView:0x7ffac3801b10](LTR)   (active)>",
    "<NSLayoutConstraint:0x600001807200 PagingScrollView.SlideView:0x7ffac3801b10.width == UIScrollView:0x7ffac1842600.width   (active)>",
    "<NSLayoutConstraint:0x6000018072f0 PagingScrollView.SlideView:0x7ffac3801b10.right == UIView:0x7ffac0d0cb40.right   (active)>",
    "<NSLayoutConstraint:0x600001818ff0 'UIView-Encapsulated-Layout-Width' UIView:0x7ffac0d0fba0.width == 414   (active)>",
    "<NSLayoutConstraint:0x600001804460 'UIViewSafeAreaLayoutGuide-left' H:|-(0)-[UILayoutGuide:0x6000002308c0'UIViewSafeAreaLayoutGuide'](LTR)   (active, names: '|':UIView:0x7ffac0d0fba0 )>",
    "<NSLayoutConstraint:0x600001805130 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x6000002308c0'UIViewSafeAreaLayoutGuide']-(0)-|(LTR)   (active, names: '|':UIView:0x7ffac0d0fba0 )>"
“”,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
而且它根本不会滚动。仅显示最后一个幻灯片视图。看起来contentView没有根据约束调整大小

以下代码负责将每个SlideView添加到ScrollView(精确地添加到内容视图):

private func setup(){
var prevLeftAnchor=contentView.leftAnchor;
对于0中的i..
几个小时后,我陷入困境,看不出问题出在哪里。我感谢你的回应


您可以查看github中的简单项目

在您的
SlideViewController.xib
中,您对
内容视图有
CenterX
约束

删除该约束,您应该能够滚动


请注意,您还有两个前导约束。因为它们是相同的,所以不会影响任何东西,但为了清晰起见,最好删除其中一个。

谢谢!你的回答帮助我解决了这个问题
private func setup() {
        var prevLeftAnchor = contentView.leftAnchor;

        for i in 0 ..< slides.count {
            slides[i].translatesAutoresizingMaskIntoConstraints = false
            contentView.addSubview(slides[i])

            slides[i].leftAnchor.constraint(equalTo: prevLeftAnchor).isActive = true
            slides[i].topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
            slides[i].widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
            slides[i].heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = true
            prevLeftAnchor = slides[i].rightAnchor;
        }

        slides.last?.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true;
}