我在視圖中有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];
}
}
如果我理解正確的,你有5個下拉菜單,如果你點擊一個和其他一些一個是開放的,你要關閉它? –
是的。這是正確的。和我只有一個視圖打開沒有不同的所有 –