Swift UIScrollView不滚动但响应setContentOffset和Delegate响应 [英] Swift UIScrollView not scrolling but responding to setContentOffset and Delegate responds

查看:570
本文介绍了Swift UIScrollView不滚动但响应setContentOffset和Delegate响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里用 UIScrollView 获取一个非常奇怪的事件,它只是拒绝滚动。我在我的StoryBoard中设置它并在我的 ViewDidLoad 中正确设置 contentSize 。我仔细检查以确保它是 Scrollable 等,但它只是不起作用。我设置了 scrollView.setContentOffset(),它用一个可爱的动画滚动得很好,并调用了 ScrollViewDidScroll 委托get。那么,有什么理由说它可能没有用拖动手势滚动?

Getting a really bizarre incident with a UIScrollView here which just refuses to scroll. I set it up in my StoryBoard and set the contentSize correctly in my ViewDidLoad. I double checked to ensure that it was Scrollable etc, yet it's just not working. I set scrollView.setContentOffset() and it scrolls fine with a lovely animation and the ScrollViewDidScroll delegate get's called. So, with that said any reason why it may not be scrolling with drag gestures?

我检查的东西:

- UserInteraction 启用自身,所有子/超级视图

- 可滚动

- 切换: DelaysContentTouches CancellableContentTouches

Things I've checked:
- UserInteraction Enabled on itself, all sub/superviews.
- Scrollable.
- Toggled: DelaysContentTouches and CancellableContentTouches.

我没有想法。目前使用 Xcode 6 Beta 1 。任何帮助将不胜感激。

I'm out of ideas. Currently using Xcode 6 Beta 1. Any help would be appreciated.

问候,

迈克

Regards,
Mike

推荐答案

由于自动布局,它不会使用拖动手势滚动。在viewDidLoad中,自动布局将在您定义内容后重置内容大小。您有两种选择:可以禁用自动布局,也可以在viewDidLayoutSubviews中设置contentSize。

It isn't scrolling with drag gestures because of auto layout. In viewDidLoad, auto layout will reset the content size after you define it. You have two options: you can disable auto layout, or you can set contentSize in viewDidLayoutSubviews.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    scrollView.contentSize = CGSize(width:10, height:10)
}

这篇关于Swift UIScrollView不滚动但响应setContentOffset和Delegate响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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