iphone - 确定触摸是否发生在uiview的子视图中 [英] iphone - determine if touch occurred in subview of a uiview

查看:129
本文介绍了iphone - 确定触摸是否发生在uiview的子视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)事件
{
如果(触摸发生在子视图中){
return YES;
}

return NO;
}

我可以在if语句中添加什么?我想检测子视图中是否发生触摸,而不管它是否位于UIView的框架内。

解决方案

尝试:

   - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 
{
return CGRectContainsPoint(subview.frame,point);
}

如果要在您实现的视图内部返回YES这个方法,使用这个代码:(如果你想添加手势识别器到位于容器边界之外的子视图)

   - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 
{
if([super pointInside:point withEvent:event])
{
return YES ;
}
else
{
return CGRectContainsPoint(subview.frame,point);
}
}


In a subclass of UIView I have this:

    -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
       if(touch occurred in a subview){
         return YES;
       }

       return NO;
    }

What can I put in the if statement? I want to detect if a touch occurred in a subview, regardless of whether or not it lies within the frame of the UIView.

解决方案

Try that:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    return CGRectContainsPoint(subview.frame, point);
}

If you want to return YES if the touch is inside the view where you implement this method, use this code: (in case you want to add gesture recognizers to a subview that is located outside the container's bounds)

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    if ([super pointInside:point withEvent:event])
    {
        return YES;
    }
    else
    {
        return CGRectContainsPoint(subview.frame, point);
    }
}

这篇关于iphone - 确定触摸是否发生在uiview的子视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆