Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如果([labelView.layer containsPoint:touchPoint])在Xcode中不工作_Iphone_Objective C_Ios_Cocoa Touch - Fatal编程技术网

Iphone 如果([labelView.layer containsPoint:touchPoint])在Xcode中不工作

Iphone 如果([labelView.layer containsPoint:touchPoint])在Xcode中不工作,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,有谁能告诉我,我在拖动和释放鼠标时,使用了带有UIPangesture的可拖动标签 CGPoint touchPoint = [panGesture locationInView:self.view]; 现在我想检查这个标签拖到哪个标签上。为此,我使用以下代码 for(UILabel *labelView in self.view.subviews){ if ([labelView isMemberOfClass:[UILabel class]]) { NSLog(@

有谁能告诉我,我在拖动和释放鼠标时,使用了带有
UIPangesture
的可拖动标签

CGPoint touchPoint = [panGesture locationInView:self.view];
现在我想检查这个标签拖到哪个标签上。为此,我使用以下代码

for(UILabel *labelView in self.view.subviews){
    if ([labelView isMemberOfClass:[UILabel class]]) {

        NSLog(@"%@",NSStringFromCGPoint(touchPoint ));

        NSLog(@"%@",NSStringFromCGRect(labelView.layer.frame));

        if([labelView.layer containsPoint:touchPoint]){

            int i=[[labelView.subviews objectAtIndex:0] tag];

            NSLog(@">>>> %d",i);
        }
    }
}

传递给手势处理程序方法的panGesture具有属性“view”,该属性指向您使用识别器设置的UILabel对象

编辑: *--上面的回答是错误的。谢谢杰基指点我--*

view的hitTest:withEvent:method将返回该点的视图。将零传递给withEvent:

如果self.view也有UILabel以外的子视图,并且希望避免返回其中一个,请调用

bool CGRectContainsPoint (
   CGRect rect,
   CGPoint point
);
对于每个标签。对rect传递帧,对点传递接触点

for(UILabel *labelView in self.view.subviews){
    if ([labelView isMemberOfClass:[UILabel class]]) {
        if(CGRectContainsPoint(labelView.frame,touchPoint)){
            int i=[[labelView.subviews objectAtIndex:0] tag];
            NSLog(@">>>> %d",i);
        }
    }
}
编辑: .layer的containsPoint:无法工作的原因:

点是接收器坐标系中的一个点

在您的代码中,接触点位于self.view的坐标系中,该坐标系不同于任何标签的坐标系

谢谢您的回复。 这对我有用

if ([labelView.layer containsPoint:[labelView.layer convertPoint:touchPoint fromLayer:labelView.layer.superlayer]] == TRUE)

但是你的答案也是正确的,我已经检查过了。

我想知道正确缩进代码有多难,至少在你需要别人帮助的时候。他想知道他现在用
UILabel
触摸的是哪个
UILabel
他已经结束了拖动。。。