我有这个代码默认隐藏 UIPickerView :
- (void)viewDidLoad
{
[super viewDidLoad];
[_memberList setAlpha:0];
}
当点击按钮时,这段代码显示 UIPickerView :
- (IBAction)buttonChooseMember {
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[_memberList setAlpha:1];
} completion:nil];
}
最后一件事是,当用户点击任何地方时隐藏键盘:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]]) {
[txt resignFirstResponder];
}else if ([txt isKindOfClass:[UIPickerView class]]) {
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[_registerMLMList setAlpha:0];
} completion:nil];
}
}
}
但所有这些只是给我“出现”动画,因为它只是将 Alpha 值从 0 更改为 1(反之亦然)。不像 iOS 键盘那样向上或向下滑动。
我尝试使用下面的动画在我的 UIPickerView 上设置 iOS 键盘的外观和感觉:
- (IBAction)hidePicker {
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight * -2); // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
} completion:nil];
}
- (IBAction)showPicker {
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight); // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
} completion:nil];
}
我喜欢这个动画,它看起来像 iOS 键盘动画,但是这个动画的问题是......当我的应用程序加载时, UIPickerView 已经出现了。第一次加载时如何隐藏它?
谢谢你。