Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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 触摸位置、框架。CGRectContainsPoint未返回true_Iphone_Ios_Uiimageview_Uitouch_Cgrect - Fatal编程技术网

Iphone 触摸位置、框架。CGRectContainsPoint未返回true

Iphone 触摸位置、框架。CGRectContainsPoint未返回true,iphone,ios,uiimageview,uitouch,cgrect,Iphone,Ios,Uiimageview,Uitouch,Cgrect,我有多个UIImageView子类: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint _location = [touch locationInView:touch.view]; [self processTouch:_location]; } } -(void)p

我有多个UIImageView子类:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    for (UITouch *touch in touches) {

        CGPoint _location = [touch locationInView:touch.view];
        [self processTouch:_location];
    }


}





-(void)processTouch:(CGPoint)location {



    DLog(@"location: %f .. bounds: %f : %f" ,location.x, [twoThirdOfTheWayCoordinateX floatValue], [oneThirdOfTheWayCoordinateX floatValue]);



    if(CGRectContainsPoint(self.frame, location)) {

        DLog(@"1");

        if(location.x > [twoThirdOfTheWayCoordinateX floatValue]){

            [self oneStar];

        } else if (location.x < [oneThirdOfTheWayCoordinateX floatValue]) {

            [self zeroStars];

        } else if( [twoThirdOfTheWayCoordinateX floatValue] >= location.x && location.x >= [oneThirdOfTheWayCoordinateX floatValue]){

            [self halfStars];

        }

    }

}
从未接到过电话

为什么会这样?第一个DLog被调用

用于初始化实例的代码:

self.instance = [[Class alloc] initWithFrame:CGRectMake(10, 10, 50 , 50)];
self.instance.userInteractionEnabled = YES;
self.instance.image = [UIImage imageNamed:@"0-0.png"];
[self.view addSubview: self.instance];
[self.instance setNeedsDisplay];

将self.frame替换为self.bounds修复了该问题

在freenode上发布iphonedev,这是对8月份的致敬

self.instance = [[Class alloc] initWithFrame:CGRectMake(10, 10, 50 , 50)];
self.instance.userInteractionEnabled = YES;
self.instance.image = [UIImage imageNamed:@"0-0.png"];
[self.view addSubview: self.instance];
[self.instance setNeedsDisplay];