如何在iphone中单击外部时隐藏下拉列表
在iphone中单击外部时,如何关闭或隐藏下拉列表如何在iphone中单击外部时隐藏下拉列表,iphone,objective-c,xcode,Iphone,Objective C,Xcode,在iphone中单击外部时,如何关闭或隐藏下拉列表 -(void)RecommendDropDownSelect { dropDown=[[DropDownView alloc]initWithArrayData:arr_RecommendName cellHeight:30 heightTableView:100 paddingTop:-100 paddingLeft:10 paddingRight:20 refView:txt_Recommend animation:BLENDIN ope
-(void)RecommendDropDownSelect
{
dropDown=[[DropDownView alloc]initWithArrayData:arr_RecommendName cellHeight:30 heightTableView:100 paddingTop:-100 paddingLeft:10 paddingRight:20 refView:txt_Recommend animation:BLENDIN openAnimationDuration:0.5 closeAnimationDuration:0.5];
dropDown.delegate=self;
[scr_View addSubview:dropDown.view];
[dropDown openAnimation];
btn_RecommendDropDown.enabled=NO;
}
-(void)dropDownCellSelected:(NSInteger)returnIndex
{
btn_RecommendDropDown.enabled=YES;
txt_Recommend.text=[arr_RecommendName objectAtIndex:returnIndex];
}
试试这个:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
if(dropDown)
{
[drdropDown.view removeFromSuperView];
}
}
或
除了子类化
UIView
和覆盖touchsbegind
之外,如果使用UIViewController
首先,为视图设置轻触手势:
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDropDown)];
[gestureRecognizer setCancelsTouchesInView:NO];
[self.view addGestureRecognizer:gestureRecognizer];
然后实现隐藏下拉列表的方法:
- (void)hideDropDown
{
if ((dropDown != nil) && (dropDown.view != nil))
{
[drdropDown.view removeFromSuperview];
}
}
iPhone me下拉列表kab se aa gaya?使用点击手势隐藏下拉列表您可以使用(无效)触摸开始:查看或向视图添加点击手势,然后点击隐藏/删除下拉视图。这有什么大不了的吗?谢谢Owen对你的帮助,但如果我从我的文本字段的下拉列表中访问一些值,我需要再多一个帮助。我必须长时间按该值才能在文本字段中获得该值。那么,我如何只需单击一下它就可以轻松访问它?你能为你的下拉列表发布源代码吗?还有,请让它成为另一个stackoverflow问题,这样更多的人可以帮助:)我会选择第二个问题,用alpha隐藏菜单。请记住,删除和添加视图会占用更多内存,实际上,在创建视图后,您会分配内存,并且每次都会将其删除。
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDropDown)];
[gestureRecognizer setCancelsTouchesInView:NO];
[self.view addGestureRecognizer:gestureRecognizer];
- (void)hideDropDown
{
if ((dropDown != nil) && (dropDown.view != nil))
{
[drdropDown.view removeFromSuperview];
}
}