xcode 如何在单击按钮时显示和隐藏 uipickerview?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4104872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show and hide the uipickerview on button click?
提问by Gladiator10
Possible Duplicates:
Hiding/ Showing UIPickerView
可能的重复:
隐藏/显示 UIPickerView
How to show and hide the uipickerview on button click ?
如何在按钮单击时显示和隐藏 uipickerview?
回答by Ryan
That's not standard behavior for an iOS app, but if you want to do it, I would animate the picker up from the bottom of the screen to the location in which you want it to appear when the button is tapped the first time, and then animate it back down below the screen when the button is tapped again, or something to that effect.
这不是 iOS 应用程序的标准行为,但如果您想这样做,我会将选择器从屏幕底部动画化到第一次点击按钮时您希望它出现的位置,然后再次点击按钮时,将其设置回屏幕下方的动画,或类似的效果。
To do this, you would register an action handler on your UIButton using -addTarget:action:forControlEvents:. In your action handler method, check a member variable to determine if the picker is already visible. If the view isn't visible yet, create a new view in a frame that is below the screen, add it to your main view, and animate its frame onto the screen and set your member variable to indicate the picker is visible. The next time the user taps the button, animate the frame of your picker view back offscreen and remove it from your view.
为此,您将使用 -addTarget:action:forControlEvents: 在 UIButton 上注册一个动作处理程序。在您的操作处理程序方法中,检查成员变量以确定选择器是否已经可见。如果视图尚不可见,请在屏幕下方的框架中创建一个新视图,将其添加到主视图中,并将其框架设置为屏幕上的动画,并设置您的成员变量以指示选择器可见。下次用户点击按钮时,将选择器视图的框架动画返回屏幕外并将其从视图中删除。