我有一个UIPickerView有2个组件,用户可以选择一种字体和一种字体大小。解除UIPickerView一旦用户选择了所有的行
我想在用户同时选择两个时关闭视图。
我可以以某种方式使用didSelectRow:inComponent
方法执行此操作吗?
我有一个UIPickerView有2个组件,用户可以选择一种字体和一种字体大小。解除UIPickerView一旦用户选择了所有的行
我想在用户同时选择两个时关闭视图。
我可以以某种方式使用didSelectRow:inComponent
方法执行此操作吗?
是的,如果您记录提供给该方法的component
,那么当所有组件都有选择时,您可以解散。
请注意,用户可能不太喜欢它,并且使用完成按钮在选取器上方添加工具栏可能会更好。
我建议建立一个容器,以便容纳选择器和工具栏(子视图),然后显示/隐藏与任何你喜欢的动画容器视图(而不是如果,你目前所显示的选择器视图)。选取器和工具栏不需要以任何方式链接,只需在容器中很好地布置即可。
我将如何添加一个这样的工具栏?我在obj-c中还是比较新的。 也谢谢你今天 – Exothug
我希望它会帮助你
UIActionSheet *action = [[UIActionSheet alloc] init];
action.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView *pickerFromage=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 44, 0 , 0)];
UIToolbar *pickerAgeToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerAgeToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerAgeToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(PickerDoneClick)];
[doneBtn setTintColor:[UIColor blackColor]];
[barItems addObject:doneBtn];
[pickerAgeToolbar setItems:barItems animated:YES];
pickerFromage.delegate=self;
pickerFromage.dataSource=self;
pickerFromage.tag=value;
pickerFromage.showsSelectionIndicator=YES;
[action addSubview:pickerAgeToolbar];
[action addSubview:pickerFromage];
[action showInView:self.view];
[action setBounds:CGRectMake(0,0, 320, 464)];`
-(void)PickerDoneClick{
[action dismissWithClickedButtonIndex:0 animated:YES];
action=nil;
}
你可以这样来做:
拿一个UIView在厦门国际银行,然后添加一个UIPickerView和它的UIButton的工具栏。将该委托给UIPickerView并将操作分配给UIButton。以UIView的出口和你的实现文件(即.m文件)。隐藏UIView并将帧分配到屏幕的底部。比方说你已经把视图命名为myPickerView。
myPickerView.frame = CGRectMake(CGRectGetMinX(self.view.bounds),
CGRectGetMaxY(self.view.bounds),
CGRectGetWidth(myPickerView.frame),
CGRectGetHeight(myPickerView.frame));
myPickerView.hidden = YES;
这样做后,可以通过向上在动画块重新设置帧从底部到动画视图,并且还可以取消隐藏它。
当您按完成时,再次为视图设置动画并设置框架如上。
下面是动画
- (IBAction)showPicker:(UIButton *)sender {
self.myPickerView.hidden = NO;
[UIView animateWithDuration:0.5 animations:^{
[self.myPickerView setFrame:CGRectMake(0,
100,
CGRectGetWidth(self.myPickerView.frame),
CGRectGetHeight(self.myPickerView.frame))];
}];
}
行动完成按钮的代码:
-(IBAction)doneClicked:(id)sender {
self.myPickerView.hidden = NO;
[UIView animateWithDuration:0.5 animations:^{
[self.myPickerView setFrame:CGRectMake(CGRectGetMinX(self.view.bounds),
CGRectGetMaxY(self.view.bounds),
CGRectGetWidth(self.myPickerView.frame),
CGRectGetHeight(self.myPickerView.frame))];
}];
}
希望这有助于。
你想要什么?当用户从任何一个组件中选择时,你需要从两个组件中获取选定的项目?还隐藏pickerView呢? – iPatel
Exothug你可以参考我给出的下面的代码 – Romance
你可以检查编辑的答案 – Romance