UIScrollView 内的 UIDatePicker - iPhone 应用程序
如何在 iPhone 应用程序中的 UIScrollView 内使用 UIDatePicker。我无法滚动选择器上的日期,因为它认为我的手指正在控制 UIScrollView。我正在尝试将 UIDatePicker 添加到我的 UIScrollView,它位于我的 UIViewController 内部。
How can I use a UIDatePicker inside of a UIScrollView in my iPhone app. I can't scroll through the dates on the picker, because it thinks my finger is controlling the UIScrollView instead. I'm trying to add a UIDatePicker to my UIScrollView, which is inside of my UIViewController.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试将滚动视图的
delaysContentTouches
属性设置为 NO。不过,更好的方法是重新考虑你的用户界面。在小型设备上,日期选择器大约占据一半的屏幕。即使您可以滚动日期选择器而不是滚动视图,您也会将用户置于难以滚动滚动视图的位置。他们必须弄清楚,如果他们想要滚动滚动视图,则需要触摸选择器的上方或下方……这不太好用。
一种解决方案可能是让用户点击日期,然后呈现带有日期选择器的模式视图控制器。这样用户就可以选择一个新的日期,而不会出现任何关于滚动的歧义。
You might try setting the scroll view's
delaysContentTouches
property to NO.Better, though, would be to rethink your UI. A date picker takes up about half the screen on a small device. Even if you can get the date picker to scroll instead of the scroll view, you'll put the user in a position where it's going to be hard to scroll the scroll view. They'll have to figure out that they'll need to touch above or below the picker if they want to scroll the scroll view... it's just not going to be nice to use.
One solution might be to let the user tap a date, and then to present a modal view controller with a date picker. That'd let the user pick a new date without any ambiguity about scrolling.
经过几次试验,我发现这个问题的最佳解决方案是对包含日期选择器的滚动视图进行子类化,并进行命中测试以查看用户是否试图触摸选择器。我从这个问题中找到并改编了下面的代码 UIScrollView 内带有页面的 UIDatePicker
After a few trials, I found the best solution to this problem was to subclass the scroll view that contains your date picker and do a hit test to see whether the user is trying to touch the picker. I found and adapted the code below from this question UIDatePicker inside UIScrollView with pages
另一种解决方案是当您想从选择器中选择数据时将其从底部向上弹出。添加到您的视图(self.view)。
another solution is pop it upward from bottom when you want to select data from picker. add to ur view (self.view).