故事板 UIScrollView contentSize?

时间:2022-11-03
本文介绍了故事板 UIScrollView contentSize?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我觉得我已经触及了阻止它的每一个可能的原因,但是我的 Storyboard 中有一个 UIScrollView 与一个插座相连,在 viewDidLoad 中我设置了 contentSize 以便我可以滚动(是的,比我的框架大大小)!

I feel like I have touched on every single possible cause for stopping this, but I have a UIScrollView in my Storyboard hooked up with an outlet and in the viewDidLoad I set the contentSize so that I can scroll (yes bigger than my frame size)!

但是,无论我更改什么,我都无法滚动!我的滚动视图中有几个文本字段并启用了弹跳功能,因此我可以看到,在使用其中的子视图测试其上下移动时,但是无论我将 contentSize 设置为什么,我都无法滚动.

However, whatever I change, I just can't scroll! I have a couple of textfields in my scrollview and bouncing enabled so I can see that when testing its moves up and down with my subviews in it but whatever I set the contentSize to I just can't scroll.

有什么我可能遗漏/应该检查的吗?这是在故事板中使用 UIScrollView 的已知问题吗?

Anything I might be missing/should check? Is this a known issue with UIScrollView being used in a storyboard?

更奇怪的是,我可以这样做:[scrollView setBackgroundColor:[UIColor blueColor]]; 我有一个蓝色滚动视图!但是设置内容大小失败.

Whats even stranger is, I can do something like this: [scrollView setBackgroundColor:[UIColor blueColor]]; and I have a blue scroll view! But setting content size fails.

我唯一的代码(否则滚动视图只是放入情节提要视图控制器中):

My only code (otherwise scrollview is just dropped into storyboard view controller):

-(void)viewDidAppear:(BOOL)animated
{
    [scrollView setContentSize:CGSizeMake(320, 640)];
}

记录的帧,按预期出现:

Logged frame, comes out as expected:

width: 320.00
height: 504.00

编辑 2

事实证明,在我的故事板中删除滚动视图的任何子视图可以让它滚动得很好.如果我通过情节提要向它添加任何子视图,即使是一个空白的全新 UIButton,它也不会应用 contentSize/允许滚动.

Edit 2

Turns out that removing any subviews of the scroll view in my storyboard lets it scroll just fine. If I add any subview to it at all via the storyboard, even a blank brand new UIButton it just won't apply the contentSize/allow scrolling.

推荐答案

使用ViewDidLayoutSubview

use ViewDidLayoutSubview

- (void)viewDidLayoutSubviews
{
    [_scrollView setContentSize:CGSizeMake(320, 500)];
}

UIViewController的方法调用顺序如下

UIViewController's method invoke sequence is as below

  • awakeFromNib
  • viewDidLoad
  • viewWillAppear
  • viewWillLayoutSubviews
  • viewDidLayoutSubviews
  • viewDidAppear

这篇关于故事板 UIScrollView contentSize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一条:UIScrollView 的滚动方向 下一条:UITableView 顶部的 UISearchBar 可以隐藏但靠近 UINavigationBar

相关文章

最新文章