UIScrollView 不起作用 [英] UIScrollView won't work

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

问题描述

我整个上午都在为此挣扎 3 个多小时,我真的快疯了!

I've been struggling with this all morning for more than 3 hours now and I'm literally going insane!

我正在使用 Xcode 4.6 为 iOS 6 创建一个 Storyboard 应用程序.我将一个 UIScrollView 拖放到 ViewController 中.在设计了 Scroll 视图的可视部分之后,我使用它的手柄垂直拉伸它并将它向上推一点,这样我就可以看到该部分来设计屏幕的其余部分.完成后,我将滚动视图定位回以适应视图.但是我没有调整滚动视图的大小以匹配来自 IB 的视图的大小.

I'm creating a Storyboard app for iOS 6 using Xcode 4.6. I dragged and dropped a UIScrollView to a ViewController. After designing the viewable part of the Scroll view, using its handles I stretched it vertically and pushed it up a bit so that that part is visible for me to design the rest of the screen. After I was done I positioned the scroll view back to fit the view. But I did not resize the scroll view to match the size of the view from the IB.

我在 viewDidLayoutSubviews 方法中添加了以下代码行(使用该方法而不是 viewDidLoad 因为 Chris 的评论 此处).

I added the following line of code in the viewDidLayoutSubviews method (Used that method instead of viewDidLoad because of Chris' comment here).

self.scrollView.contentSize = self.view.frame.size;

代码被执行,但滚动条不会出现,它滚动根本不起作用!我经历了几乎所有关于 SO 的问题和答案,并尝试了一切但无济于事.

The code gets executed but the scroll bars won't appear and it scrolling does not work at all! I went through almost all the questions and answers here on SO regarding this and tried everything but to no avail.

我也在此处附上了可运行的 Xcode 项目.

I attached the runnable Xcode project here as well.

请告诉我我应该怎么做才能使这个工作正常进行.我永远对 Apple 感到沮丧.

Please tell me what I should do to get this working. I'm eternally frustrated with Apple.

谢谢.

推荐答案

不过这很容易.删除 viewDidLayoutSubviews 方法并用以下代码替换 viewDidLoad.高度 672 目前是硬编码的.. 但它会根据滚动视图中的内容而改变.

It is quite easy though. Remove viewDidLayoutSubviews method and replace viewDidLoad with following code. Height 672 is hardcoded for now.. but it will change as per the content in the scrollview.

- (void)viewDidLoad
{
    [super viewDidLoad];
     self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 627);
    self.scrollView.frame = self.view.frame;
}

在故事板中,执行以下步骤1. 选择查看并转到尺寸检查器.2. 从约束中选择底部空间.3. 编辑底部空间约束并将常量值设置为 0(为 -211).

And in the storyboard, perform following steps 1. Select View and go to size inspector. 2. Select Bottom Space from the contraints. 3. Edit Bottom space constraint and set constant value to 0 (it was -211).

链接是更新的源代码:http://www54.zippyshare.com/v/37137086/file.html

希望这会有所帮助.

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

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