Storyboard UIScrollView contentSize?(故事板 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 contentSize?
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01