gpt4 book ai didi

iphone - UIView 之外的触摸

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:41 24 4
gpt4 key购买 nike

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
NSLog(@"The tag %i",touch.view.tag);
if( [touch.view isKindOfClass:[UIScrollView class]] ) {
for( UIView *checkview in [self.view subviews] ) {
if( [checkview tag] == 1 ) {
infoIsVisibile = NO;
[info removeFromSuperview];
}
}
}
[super touchesBegan:touches withEvent:event];
}

谁能帮帮我,这只会检测 subview 内的触摸,而不是主视图。

最佳答案

您可以将 UIGestureRecognizer 连接到您感兴趣的 View 。

(一般来说,手势识别器是一种更强大的机制,用于检测任意 View 中的触摸,并且它们可以很好地处理 UIWebViews 和 UIScrollViews 等倾向于吃掉传统触摸事件的 View 。)

这是一个片段:

UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSingleDoubleTap:)];
singleFingerDTap.numberOfTapsRequired = 2;
[self.theView addGestureRecognizer:singleFingerDTap];
[singleFingerDTap release];

(此代码来自下面的链接文档——请注意,self.theView 可能是作为当前对象的成员存储的一些随机 View 。)

您会惊讶(或震惊)手势识别器在多大程度上简化了您的代码并减少了怪异现象。

这是 Apple 文档的链接:

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

关于iphone - UIView 之外的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10924233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com