简体   繁体   English

在UIScroll视图上添加UIPicker?

[英]Add a UIPicker on a UIScroll View?

I designed an app with mainly uses UIPicker, but I don't have space to use more then 10 pickers. 我设计的应用程序主要使用UIPicker,但我没有足够的空间使用超过10个选择器。

Of course, all the pickers are connected to a UITextField. 当然,所有选择器都连接到UITextField。 So if you press a TextField a Picker will show. 因此,如果您按下TextField,将显示一个选择器。 I'm Trying to add a UIScrollView so I can add more TextField which when pressed shows a UIPicker. 我正在尝试添加UIScrollView,以便可以添加更多的TextField,当按下时会显示UIPicker。

Is it Possible? 可能吗? Can I view two views at the same time? 我可以同时查看两个视图吗? I would really appreciate it, if someone can give me a hand. 如果有人可以帮我,我将非常感激。

Thank you 谢谢

Yes you can have more than one view onscreen at a time. 是的,您一次可以在屏幕上看到多个视图。 Simply make the UIPickerView as subview of the UIScrollView: 只需将UIPickerView作为UIScrollView的子视图即可:

UIScrollView* scroll = [[UIScrollView alloc] init];
UIPickerView* picker = [[[UIPickerView alloc] init] autorelease];
[scroll addSubView: picker];

This certainly seems possible. 这当然可能。 You just need a scroller which will accomodate all your clickable-textFields AND will scroll at the same time right? 您只需要一个可以容纳所有clickable-textFields并且可以同时滚动的滚动条,对吗?

Add a scrollView to your main view, and add all your textFields as subviews of the scrollView. 将scrollView添加到您的主视图,并将所有textField添加为scrollView的子视图。 Make sure the contentSize of the scrollView is set to accomodate all the textFields. 确保将scrollView的contentSize设置为容纳所有textField。 The UITextField will working for the tap, and it will not interfere in any way with the swipe of the scroller. UITextField将适用于轻按,并且不会以任何方式干扰滚动条的滑动。

I assume you're trying to create a sort of data entry form here? 我假设您正在尝试在此处创建一种数据输入表单? Where the data values are discrete and must be chosen from a picker? 数据值是离散的,必须从选择器中选择? If so, we've done this sort of thing plenty of times, so yeah, its totally doable. 如果是这样,我们已经做了很多次这样的事情,是的,它完全可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM