如何识别特定视图中的触摸

Kum*_*onu 6 iphone uitouch

如何触摸特定视图.

我在用

CGPoint Location = [[touches anyObject] locationInView:self.view ];
Run Code Online (Sandbox Code Playgroud)

但是只有在单击特定的子视图时才想触发操作.
这该怎么做.

Kum*_*onu 8

我自己得到了答案......但感谢其他帮助我的人

这里是

UITouch *touch ;
touch = [[event allTouches] anyObject];


    if ([touch view] == necessarySubView)
{
//Do what ever you want
}
Run Code Online (Sandbox Code Playgroud)


Sat*_*Sat 7

试试这个

//here enable the touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // get touch event
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];

    if (CGRectContainsPoint(yoursubview_Name.frame, touchLocation)) {
        //Your logic
        NSLog(@" touched");
    }
}
Run Code Online (Sandbox Code Playgroud)