我的接口文件上有这个:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDataSource>
// PickerView Array
@property (strong, nonatomic) NSArray *pickerNames;
@property (strong, nonatomic) NSArray *pickerValues;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
- (IBAction)buttonSelectPicker;
@end
我的实现文件中有这个:
- (void)viewDidLoad
{
[super viewDidLoad];
// PickerView Array
_pickerNames = @[@"Data1", @"Data2", @"Data3", @"Data4", @"Data5"];
_pickerValues = @[@"val1", @"val2", @"val3", @"val4", @"val5"];
_picker.frame = CGRectMake(0, 1000, 320, 216);
}
所有这些代码现在都可以在我的 iPod (iOS 6.1.3) 上完美运行,但我实际上想要做的更多事情有问题......他们是......
当应用程序第一次加载时,UIPickerView 被隐藏(在屏幕区域之外)。我尝试通过添加这一行(on
viewDidLoad
),但它没有用。_picker.frame = CGRectMake(0, 1000, 320, 216);
然后当用户点击
buttonSelectPicker
按钮时, UIPickerView 出现。这行代码也不起作用:- (IBAction)buttonSelectPicker { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; _pickerviewContainer.frame = CGRectMake(0, 289, 320, 216); [UIView commitAnimations]; }
当用户点击 UIPickerView 区域外的任何地方时,它将隐藏 UIPickerView。我有这段代码可以关闭键盘,但我不知道如何修改以关闭 UIPickerView :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UIView * txt in self.view.subviews){ if ([txt isKindOfClass:[UITextField class]]) { [txt resignFirstResponder]; } } }
谢谢你...