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

问题描述

我觉得我已经触及了阻止这个的每一个可能原因,但是我的故事板中有一个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.

任何帮助表示感谢,谢谢。

Any help appreciated, thanks.

编辑:

我唯一的代码(否则scrollview只是放入了故事板视图控制器):

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

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

记录的框架,按预期出现:
宽度:320.00
身高:504.00

Logged frame, comes out as expected:width: 320.00height: 504.00

编辑2:

原来删除滚动视图的任何子视图我的故事板让它滚动得很好。如果我通过故事板添加任何子视图,即使是空白的全新UIButton它也不会应用contentSize / allow滚动。

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

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

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

05-25 17:41