2014-07-20 79 views
0

我有一个水平分页UIScrollView设置有两个页面。在scrollview中有一个“内容视图”,其中设置了约束条件,使其成为scrollview的“内容大小”。内容视图包含两个子视图,第一页和第二页。这工作正常,我可以在两页之间水平页面。没有垂直的“反弹”,因为页面正好填满了内容大小。UITextView里面的UIScrollView

我还没有添加任何东西到第一页,但是我在第二页添加了一个UITextView。此文本视图具有约束设置,以便它在第二页居中,并适合第二页。意图是,这只会显示短暂的blurb,因此scrollEnabled在文本视图中设置为NO。文字应该很容易地放在空间内而不会被切断。

我在文本视图中放置了一些虚拟文本,一切正常。然后,我稍微增加了字体。尽管文本仍然很容易放入允许的空间内,但我现在会在滚动视图上收到一个垂直“反弹” - 就好像内容大小现在垂直较大(或者插入已更改)。我已经检查过这些,并且它们与字体更改之前的字体完全一样。文本视图的内在内容大小稍大(因为字体大小增加),但同样在限制范围内。什么导致了垂直反弹?

这里是代码建立的意见和约束。请注意,这是在表视图单元格(c)内。 setInfoPager是水平分页滚动视图,并且是单元格contentView的子视图。

UIView *contentView = [[UIView alloc] init]; 
    contentView.translatesAutoresizingMaskIntoConstraints = NO; 
    [c.setInfoPager addSubview:contentView]; 

    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeRight 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeRight 
                   multiplier:1.f 
                   constant:0.f]]; 
    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeLeft 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeLeft 
                   multiplier:1.f 
                   constant:0.f]]; 
    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeTop 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeTop 
                   multiplier:1.f 
                   constant:0.f]]; 
    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeBottom 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeBottom 
                   multiplier:1.f 
                   constant:0.f]]; 

    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeWidth 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeWidth 
                   multiplier:2.0 
                   constant:0.f]]; 
    [c.setInfoPager addConstraint:[NSLayoutConstraint constraintWithItem:contentView 
                   attribute:NSLayoutAttributeHeight 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:c.setInfoPager 
                   attribute:NSLayoutAttributeHeight 
                   multiplier:1.0 
                   constant:0.f]]; 

    UIView *pageOne = [[UIView alloc] init]; 
    pageOne.translatesAutoresizingMaskIntoConstraints = NO; 
    [contentView addSubview:pageOne]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageOne 
                  attribute:NSLayoutAttributeHeight 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeHeight 
                  multiplier:1.f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageOne 
                  attribute:NSLayoutAttributeWidth 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeWidth 
                  multiplier:0.5f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageOne 
                  attribute:NSLayoutAttributeLeft 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeLeft 
                  multiplier:1.f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageOne 
                  attribute:NSLayoutAttributeTop 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeTop 
                  multiplier:1.f 
                  constant:0.f]]; 

    UIView *pageTwo = [[UIView alloc] init]; 
    pageTwo.translatesAutoresizingMaskIntoConstraints = NO; 
    pageTwo.backgroundColor = [UIColor greenColor]; 
    [contentView addSubview:pageTwo]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageTwo 
                  attribute:NSLayoutAttributeHeight 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeHeight 
                  multiplier:1.f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageTwo 
                  attribute:NSLayoutAttributeWidth 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeWidth 
                  multiplier:0.5f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageTwo 
                  attribute:NSLayoutAttributeRight 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeRight 
                  multiplier:1.f 
                  constant:0.f]]; 
    [contentView addConstraint:[NSLayoutConstraint constraintWithItem:pageTwo 
                  attribute:NSLayoutAttributeTop 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:contentView 
                  attribute:NSLayoutAttributeTop 
                  multiplier:1.f 
                  constant:0.f]]; 

    UITextView *cardSetBlurb = [[UITextView alloc] init]; 
    cardSetBlurb.scrollEnabled = NO; 
    cardSetBlurb.translatesAutoresizingMaskIntoConstraints = NO; 
    [pageTwo addSubview:cardSetBlurb]; 
    cardSetBlurb.backgroundColor = [UIColor blackColor]; 
    cardSetBlurb.textColor = [UIColor whiteColor]; 
    cardSetBlurb.userInteractionEnabled = NO; 
    cardSetBlurb.font = [UIFont fontWithName:@"AvenirNext-Regular" size:12.f]; 
    cardSetBlurb.text = @"blah blah blah sdfasdf dsfasdf asdfasdf asdfasdf asdfasdf asdfasdf asdfasdf something wicked this way comes"; 

    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeLeft 
                 relatedBy:NSLayoutRelationGreaterThanOrEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeLeft 
                 multiplier:1.f 
                 constant:0.f]]; 
    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeTop 
                 relatedBy:NSLayoutRelationGreaterThanOrEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeTop 
                 multiplier:1.f 
                 constant:0.f]]; 
    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeRight 
                 relatedBy:NSLayoutRelationLessThanOrEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeRight 
                 multiplier:1.f 
                 constant:0.f]]; 
    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeBottom 
                 relatedBy:NSLayoutRelationLessThanOrEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeBottom 
                 multiplier:1.f 
                 constant:0.f]]; 
    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeCenterX 
                 relatedBy:NSLayoutRelationEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeCenterX 
                 multiplier:1.f 
                 constant:0.f]]; 
    [pageTwo addConstraint:[NSLayoutConstraint constraintWithItem:cardSetBlurb 
                 attribute:NSLayoutAttributeCenterY 
                 relatedBy:NSLayoutRelationEqual 
                  toItem:pageTwo 
                 attribute:NSLayoutAttributeCenterY 
                 multiplier:1.f 
                 constant:0.f]]; 

回答

0

您是否尝试过简单地停止界面生成器中的Storyboard的垂直反弹?