uiviewcontroller中的多DropDownList
我在视图中有5个dropdownlist。我想打开并关闭drodownlist(UIView),如下所示:
1.如果我点击第一个按钮,它将打开下拉列表,第二次点击它将关闭。
2.如果一个下拉列表在第一个按钮点击打开,我点击第二个按钮,则第一个下拉列表将关闭,第二个下拉列表将打开。
我可以打开和关闭下拉列表(1)。但在第二种情况下,我不能。
这是我的代码。uiviewcontroller中的多DropDownList
if ([self.DropDownView isDescendantOfView:self.view])
{
[self dropDownCloseAnimation:sender withTF:nil];
[self.DropDownView removeFromSuperview];
// [self performSelector:@selector(showMenu:) withObject:sender afterDelay:0.1];
}
else
{
[self.SinupView addSubview:self.DropDownView];
[self dropDownAnimation:sender withTF:nil];
}
这里是生命的下拉列表的功能
-(void)dropDownCloseAnimation : (UIButton *)sender withTF : (UITextField *)textField
{
if (sender.tag == 203 || textField.tag == 106)
{
[UIView animateWithDuration:0.9 animations:^{
self.DropDownView.frame = CGRectMake(self.TFVehicalType.frame.origin.x, self.TFVehicalType.frame.origin.y + self.TFVehicalType.frame.size.height + 2, self.TFVehicalType.frame.size.width, 0);
} completion:nil];
}
else if (sender.tag == 204 || textField.tag == 107)
{
[UIView animateWithDuration:0.5 animations:^{
self.DropDownView.frame = CGRectMake(self.TFVehicalColor.frame.origin.x, self.TFVehicalColor.frame.origin.y + self.TFVehicalColor.frame.size.height + 2, self.TFVehicalColor.frame.size.width, 0);
} completion:nil];
}
else if (sender.tag == 205 || textField.tag == 112)
{
[UIView animateWithDuration:0.5 animations:^{
self.DropDownView.frame = CGRectMake(self.TFCity.frame.origin.x, self.TFCity.frame.origin.y + self.TFCity.frame.size.height + 2, self.TFCity.frame.size.width, 0);
} completion:nil];
}
else if (sender.tag == 206 || textField.tag == 113)
{
[UIView animateWithDuration:0.5 animations:^{
self.DropDownView.frame = CGRectMake(self.TFLocation.frame.origin.x, self.TFLocation.frame.origin.y + self.TFLocation.frame.size.height + 2, self.TFLocation.frame.size.width, 0);
} completion:nil];
}
else if (sender.tag == 207 || textField.tag == 114)
{
[UIView animateWithDuration:0.5 animations:^{
self.DropDownView.frame = CGRectMake(self.TFStatus.frame.origin.x, self.TFStatus.frame.origin.y + self.TFStatus.frame.size.height + 2, self.TFStatus.frame.size.width, 0);
} completion:nil];
}
}
1-制造阵列
2-每个下拉添加到数组您在操作屏幕
-3-上显示它时按下以打开/关闭任何后下拉菜单,让我们只是做了
4-阵列上的循环,关闭各个下拉在每次迭代
5打开寄件人之一。
快乐编码!
任何想法,然后循环? –
把每一个放在.h中,然后调用并关闭它们。这对你有帮助吗? –
我只有一个视图,而不是每个视图的不同视图。我只是在视图控制器中使用关于其按钮框架的动画添加该视图。看到我的问题。它具有密切的动画代码..同时我为开放视图编码。 –
你应该用你的逻辑,给出如下,
-(void)btn1Click{
Dropdown1Show=Yes;
DropDown2Show=NO;
DropDown3Show =NO;
DropDown4Show=NO;
}
-(void)btn2Click{
Dropdown1Show=NO;
DropDown2Show=YES;
DropDown3Show =NO;
DropDown4Show=NO;
}
-(void)btn3Click{
Dropdown1Show=NO;
DropDown2Show=NO;
DropDown3Show =YES;
DropDown4Show=NO;
}
-(void)btn4Click{
Dropdown1Show=NO;
DropDown2Show=NO;
DropDown3Show =NO;
DropDown4Show=YES;
}
我只有一个视图的所有5按钮打开下拉列表 –
@ios开发人员但是,你已经创建了五个对象的五个下拉菜单吗?如果是,那么我在哪里写了是否已经创建并且没有设置为零? –
@ios开发人员希望你从中得到一个主意。如果你的问题解决了,那么请标记答案正确 –
有不同的方法来做到这一点就像你可以使用一个下拉列表以及所有按钮以及数据源的按钮更改框架。您可以使用标签属性来区分按钮和下拉列表。通过这种方式,您可以重用您的代码并轻松处理数据流。
感谢
。但我一次只想打开一个下拉菜单。我想不出来。 –
由于没有其他对象,它一次只能显示一个下拉菜单。你必须在你的代码中处理这个。 – surendrasheoran
可以请更新您的想法与代码 –
尝试这个
This Drop down will help You.
https://github.com/BijeshNair/NIDropDown
这是一个很好的控制器,但它的工作只有一个下拉菜单,而不是多个..因为我的要求 –
创建多少个按钮你有很多对象,例如:-NIDropDown * dropDown,* dropDown2;所以它会打开所有下拉菜单。 – Rameshios
如果我理解正确的,你有5个下拉菜单,如果你点击一个和其他一些一个是开放的,你要关闭它? –
是的。这是正确的。和我只有一个视图打开没有不同的所有 –