如果点击ScrollView,则隐藏/显示按钮和UIImageVIew

时间:2013-09-02 14:26:19

标签: iphone ios objective-c scrollview

如何在Scrollview上点击隐藏/显示UIButtonImageView

修改

我在视图上只使用按钮和点按:

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

1 个答案:

答案 0 :(得分:3)

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

.h 文件中使用BOOL isTappFirstTime;并在viewDidLoad方法中写isTappFirstTime = 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;
  }
}