-(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];
}
答案 0 :(得分:2)
除了继承UIView
并覆盖touchesBegan
之外,如果您使用UITapGestureRecognizer
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];
}
}
答案 1 :(得分:1)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (touch.view==self.view) {
[dropDown removeFromSuperView];
}
}
或
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (touch.view==self.view) {
dropDown.alpha=0;
}
}
答案 2 :(得分:0)
试试这个:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
if(dropDown)
{
[drdropDown.view removeFromSuperView];
}
}