3

如何通过点击滚动视图来隐藏/显示UIButton和?ImageView

编辑:

我仅将其用于按钮并点击视图:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   UITouch *touch = [touches anyObject];
   CGPoint loc = [touch locationInView:[touch view]];
   if (!CGRectContainsPoint(btn1.frame, loc) || (!CGRectContainsPoint(btn2.frame, loc)
   {
      btn1.hidden = !btn1.hidden;
      btn2.hidden = !btn2.hidden;
   }
}
4

1 回答 1

3
UITapGestureRecognizer *scrlTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrlTapREcotTap:)];
    [scrlTap setNumberOfTapsRequired:1];
    [self.ScrollView addGestureRecognizer:scrlTap];

获取.h文件并在BOOL isTappFirstTime;方法中写入viewDidLoadisTappFirstTime = YES;

编写以下手势方法;

- (void)scrlTapREcotTap:(UITapGestureRecognizer *)gestureRecognizer
{
  if(isTappFirstTime)
  { 
       //put code of hide 

     [UIView animateWithDuration:1.0 animations:^{
           button.alpha = 0;
           imgView.alpha = 0; 
           } completion: ^(BOOL finished) {
             button.hidden = YES;
             imgView.hidden = YES;
      }];        
     isTappFirstTime = NO;
  }
  else 
  {
     // put code of show
     [UIView animateWithDuration:1.0 animations:^{
       button.alpha = 1;
       imgView.alpha = 1; 
       } completion: ^(BOOL finished) {
         button.hidden = NO;
         imgView.hidden = NO;
  }]; 
     isTappFirstTime = YES;
  }
}
于 2013-09-02T14:35:03.313 回答