如果点击 ScrollView,则隐藏/显示按钮和 UIImageVIew
Posted
技术标签:
【中文标题】如果点击 ScrollView,则隐藏/显示按钮和 UIImageVIew【英文标题】:Hide/Show Button and UIImageVIew if Tap on a ScrollView 【发布时间】:2013-09-02 14:26:18 【问题描述】:如何通过点击滚动视图来隐藏/显示UIButton
和ImageView
?
编辑:
我仅将它用于 Button 和 Tap on the View:
- (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】: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;
【讨论】:
Perfekt 谢谢 :) 我怎样才能添加这个淡出? 淡出是什么意思?? ImageView 和 Button “柔和地”隐藏在 alpha 1.0 到 0.0 之间的漂亮动画中 好的,我使用了你的代码,但“淡出”效果很好,但“淡入”不起作用,没有动画 @Nils 检查***.com/questions/9637711/… 和***.com/questions/8047536/…以上是关于如果点击 ScrollView,则隐藏/显示按钮和 UIImageVIew的主要内容,如果未能解决你的问题,请参考以下文章