【发布时间】:2011-12-17 01:51:37
【问题描述】:
我有一个我在图像中显示的屏幕。现在我希望当用户点击文本字段时出现一个选择器视图。所以我希望当键盘出现时,当Picker View出现时,视图将自动滚动。
如何在拾取器视图出现时?
提前谢谢...
【问题讨论】:
-
您要滚动选择器视图还是滚动视图以使当前问题在选择器上方可见?
标签: iphone uiviewcontroller uiscrollview uipickerview
我有一个我在图像中显示的屏幕。现在我希望当用户点击文本字段时出现一个选择器视图。所以我希望当键盘出现时,当Picker View出现时,视图将自动滚动。
如何在拾取器视图出现时?
提前谢谢...
【问题讨论】:
标签: iphone uiviewcontroller uiscrollview uipickerview
【讨论】:
我假设您希望您的应用是纵向的,因为如果它是横向的,您可以进行更改。将UIPickerView 添加到您的笔尖并将其连接到IBOutlet。然后,使用IBAction 方法制作一个按钮,以动画UIPickerView。在 .h 文件中尝试:
@interface MyViewController: UIViewController {
BOOL _pickerIsVisible;
IBOutlet UIPickerView * _picker;
}
- (IBAction)buttonMethod:(UIButton *)aButton;
在您的 .m 文件中:
- (void)viewDidLoad; {
[super viewDidLoad];
_pickerIsVisible = NO;
}
- (IBAction)buttonMethod:(UIButton *)aButton; {
if(_pickerIsVisible){
_pickerIsVisible = NO;
[UIView animateWithDuration:2.0f
animations:^{
CGPoint point = _picker.frame.origin;
point.y += 216; // The height of the picker.
_picker.frame.origin = point;
}
completion:^(BOOL finished){
// Do something here if you want.
}];
}
else{
_pickerIsVisible = YES;
[UIView animateWithDuration:2.0f
animations:^{
CGPoint point = _picker.frame.origin;
point.y -= 216; // The height of the picker.
_picker.frame.origin = point;
}
completion:^(BOOL finished){
// Do something here if you want.
}];
}
}
确保在笔尖中设置UIPickerView 的 y 坐标为 480,因此它位于视图下方。
编辑:如果您希望UIPickerView 被连接起来并像UITextField 或UITextView 的键盘一样,您可以随时连接它直到UITextField 的.inputView 属性,这也可以。
希望有帮助!
【讨论】: