本文介绍了iPhone UIButton在UIScrollView中没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发人员新手,遇到的问题与我在此处阅读的几篇文章有点类似,但似乎都没有帮助.

I'm an iPhone dev newbie, and I'm having a problem slightly similar to a few posts I read around here, but none of them seemed to help.

我创建了一个UIScrollView,其内容为UIView(子视图).在运行期间,UIView会填充标签和按钮.一切看起来都很好,滚动效果完美,但是无论我做什么,按下UIButtons都不会触发.据我所知,我尝试了此处建议的属性的多种组合,但仍然没有任何效果.恐怕我可能对该机制有误解.

I have created a UIScrollView, with a UIView as its content (a subview). During runtime, the UIView is populated with labels and buttons. Everything looks fine, scrolling works perfectly, but the UIButtons never fire when pressed, no matter what I do. I've tried many combinations of properties suggested here, to the best of my understanding, but still nothing worked. I'm afraid I might have misunderstood something about the mechanism.

我应该提到所有事情都是用代码完成的(没有IB).

I should mention that everything is done in code (no IB).

有什么建议吗?

推荐答案

我的错误(写在我的问题的评论中)没有设置contentview的框架,该框架是所有按钮的父级.结果很奇怪-我可以看到按钮子视图(这就是为什么我花了一些时间才能找到bug的原因),但是无法单击它们.哎呀!

My bug (written in the comments of my question) was not setting the frame of the contentview that was the parent of all buttons. The result was strange - I could see the button subviews (which was why it took me a while to find the bug) but could not click on them. oops!

这篇关于iPhone UIButton在UIScrollView中没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:02