2

プログラムで、iPhoneの外側をクリックしたときにドロップダウンリストを閉じたり非表示にしたりするにはどうすればよいですか?

-(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];

}
4

3 に答える 3

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];
    }
}
于 2013-01-31T10:40:16.707 に答える
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;
        }
    }
于 2013-01-31T10:33:10.310 に答える
0

これを試して:

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
   if(dropDown)
   {
      [drdropDown.view removeFromSuperView];
   }
}
于 2013-01-31T10:30:35.767 に答える