UIPageControl不遵守UIScrollView中的约束 [英] UIPageControl doesn't obey it's constraints inside UIScrollView

查看:106
本文介绍了UIPageControl不遵守UIScrollView中的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIScrollView,滚动视图中有很多视图。我正在使用自动布局,我的所有视图都以相同的方式布局:左侧和顶部间距设置为超视图,宽度和高度。一切都滚动得很好,但我的页面控制保持不变。它不会滚动滚动视图中的其他元素。是的,我做了检查滚动视图中的页面控件就像其他元素一样,是的,我已经四倍检查了页面控件的约束。它只是不会滚动。可能是什么问题呢?有标签,另一个滚动视图,文本视图,图像视图,它们都完美滚动,这只是页面视图有问题。是否有Xcode / iOS SDK的错误,或者我错过了什么?

I have a UIScrollView and there are many views inside my scroll view. I am using autolayout and all my views are layed out in the same manner: Left and top spacing to the superview, width and height set. Everything scrolls just fine, however my page control stays whereever it is. It does not scroll with the other elements inside the scroll view. YES, I did check that the page control is inside the scroll view just like the other elements, and yes, I've quadruple-checked the constraints of the page control. It just won't scroll. What could be the problem? There are labels, another scroll view, text views, images views and they all scroll perfectly, it's just the page view that is problematic. Is there a bug with Xcode/iOS SDK, or am I missing something?

更新:我的滚动视图中的所有视图都在容器视图。滚动视图和容器视图的 translatesAutoresizingMaskIntoConstraints 属性都设置为。它只是页面控件不遵守它的约束。以下是Interface Builder的截图:

UPDATE: All the views inside my scroll view are inside a container view. Both the scroll view's and the container view's translatesAutoresizingMaskIntoConstraints property is set to NO. It's only the page control that doesn't obey it's contraints. Here is a screenshot from the Interface Builder:

推荐答案

我得到了它的工作:

1)将所有视图/控件放在containerView中并将其声明为属性。

1) Putting all views/controls inside a containerView and declaring it as a property.

2)添加此代码:

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.scrollView.contentSize = self.containerView.bounds.size;
}

- (void)viewDidLoad{
    [super viewDidLoad];

    //added with containerview from g8productions
    self.containerView =  [[UIView alloc] initWithFrame:CGRectMake(36, 59, 900, 1200)];
    self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.scrollView addSubview:self.containerView];
    [self.scrollView setContentSize:self.containerView.bounds.size];
}

希望这些解决方案都适合你!

Hope either of these solutions work for you!

这篇关于UIPageControl不遵守UIScrollView中的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆