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

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

问题描述

我整个上午都在努力工作超过3个小时,我真的疯了!

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

我正在为iOS创建一个Storyboard应用程序6使用Xcode 4.6。我将 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;

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

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天全站免登陆