如何在Scrollview上点击隐藏/显示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;
}
}
答案 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;
}
}