Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Ios 按下UIImageView时记录的外部补漆事件_Ios - Fatal编程技术网

Ios 按下UIImageView时记录的外部补漆事件

Ios 按下UIImageView时记录的外部补漆事件,ios,Ios,我有一个UIButton,我在外面添加了动作润色。我有一个很好的视野 我希望执行以下操作:当用户触摸按钮并在UIImageView上释放时,我希望执行一些操作 如果用户触摸按钮并在其他视图(而不是UIImageView)中释放,则不应执行某些操作 这是我的密码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoi

我有一个UIButton,我在外面添加了动作润色。我有一个很好的视野

我希望执行以下操作:当用户触摸按钮并在UIImageView上释放时,我希望执行一些操作

如果用户触摸按钮并在其他视图(而不是UIImageView)中释放,则不应执行某些操作

这是我的密码:

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

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    NSLog(@"Touch x : %f y : %f", location.x, location.y);
    if(CGRectContainsPoint(redBtn.frame, location)){
        NSLog(@"red button pressed");
    }else if (CGRectContainsPoint(blueBtn.frame, location)){
        NSLog(@"blue button pressed");
    }
}

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

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

}

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


    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    if(CGRectContainsPoint(firstImageView.frame, location)){
        if(redFlag){
            [firstImageView setBackgroundColor:[UIColor redColor]];
        }
        else if(blueFlag){
            [firstImageView setBackgroundColor:[UIColor blueColor]];
        }

        NSLog(@"touch ended in first view");
    }else if(CGRectContainsPoint(secondImageView.frame, location)){

        if(redFlag){
            [secondImageView setBackgroundColor:[UIColor redColor]];
        }
        else if(blueFlag){
            [secondImageView setBackgroundColor:[UIColor blueColor]];
        }

        NSLog(@"touch ended in second view");
    }

}

使用
touchesend
执行此操作。要检查按钮是否按下,请使用BOOL,然后在触摸结束时,使用
touch.view==imageView
然后执行所需操作

在按钮单击事件时,将布尔变量设置为“是”,以确保按下该变量。现在,在与UIResponser的接触中写入

UITouch *touch = [touches anyObject]; 
if (touch.view == imageView) 
   {
      // do the required thing here
   }

请详细说明。我没有正确地得到它。我已经附上了我的代码,请过目一下。我在UIImage视图中获得了良好的触摸效果,但在UIButton中未记录触摸。我需要获得触摸输入按钮。触摸开始于UIButton,触摸结束于UIImageGet触地事件,然后触摸结束UIImage