UISwitch内UIScrollview几乎不可能使用 [英] UISwitch within UIScrollview nearly impossible to use
问题描述
我在UIScrollView中的视图底部使用了一个UISwitch-Component。
现在出现的问题是,切换几乎不可能滑动,因为UIScrollView似乎支配用户输入。
切换工作非常好,通过点击开关,但从我的角度来看,大多数用户切换UISwitch而不是轻敲。
您有任何人遇到相同或类似的问题,并设法找出解决方案吗?
提前thx
sam
make:如果您的内容是水平滚动,则用户在开关上方滑动是不明确的 - 是否意味着他们要滚动或切换开关?
最简单的解决方案是修改您的UI,以使这种歧义消失。例如,如果滚动的 contentSize
不大于滚动视图的边界,则它不能水平滚动,水平滑动将始终激活开关。 / p>
如果你想允许水平滚动,那么将 UISwitch
替换为 UIButton
会在触摸时切换,类似于播放/暂停按钮。
另一方面,如果您不想修改您的UI,您可以随时执行:
myScrollView.delaysContentTouches =
这将导致您的切换立即获得触摸,而不是让他们去 UIScrollView
。 更多信息。 (你也可以在Interface Builder中设置这个布尔值,正如Squeegy指出的那样。)
I'm using a UISwitch-Component at the bottom of a view that sits within a UIScrollView. Now the problem that appeared, is that the switch is nearly impossible to swipe because the UIScrollView seems to dominate the userinput.
Switching works very well by tapping the switch, but from my point of view, most users "switch" the UISwitch instead of tapping.
Did anyone of you face the same / or similar problems and managed to come up with a solution?
thx in advance
sam
You have a design decision to make: if your content is meant to scroll horizontally, then a user swipe over a switch is ambiguous -- does it mean they want to scroll, or toggle the switch?
The easiest solution is to modify your UI so that this ambiguity disappears. For example, if the scroll's contentSize
is not wider than the bounds of the scroll view, then it can't scroll horizontally, and a horizontal swipe will always activate the switch.
If you do want to allow horizontal scrolling, then it makes sense to replace the UISwitch
with a UIButton
that toggles on touch, similar to a play/pause button.
On the other hand, if you don't want to modify your UI, you could always just do:
myScrollView.delaysContentTouches = NO;
This will cause your switch to "get" the touches immediately, rather than have them go to the UIScrollView
first. More info here. (You can also set this boolean in Interface Builder, as pointed out by Squeegy.)
这篇关于UISwitch内UIScrollview几乎不可能使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!