2011-03-04 13 views

Respuesta

8

Tengo la respuesta a mí mismo ... pero gracias otra que me ayudaron en esta

aquí es

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


    if ([touch view] == necessarySubView) 
{ 
//Do what ever you want 
} 
1

Debe crear una subclase (o crear una categoría) de UIView y anular la

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

donde redirigir el mensaje al delegado correspondiente.

+0

no usted no necesita hacer eso ... ver mi propia respuesta que encontré solo unos minutos Hace ... –

+0

Parece que he entendido mal su pregunta. – Max

+0

+1 ..buena alternativa, si se debe realizar un gran trabajo en una subvista, gracias –

0

Did u tratar

CGPoint Location = [[touches anyObject] locationInView:necessarySubView ]; 
+0

no, esto da la ubicación en una vista y no en la vista que se tocó .... –

7

Prueba este

//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"); 
    } 
} 
+0

+1 buena respuesta, pero por favor también marque la mía. ... –

+0

Ya ... está muy bien. + 1. – Sat

1
// here Tiles is a separate class inherited from UIView Class 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    if ([[touch view] isKindOfClass:[Tiles class]]) { 
     NSLog(@"[touch view].tag = %d", [touch view].tag); 
    } 
} 

como esto se puede encontrar punto de vista o se toca subvista

1

Heres una versión swift3 sin multitouch:

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 
    if let touch = touches.first, self.bounds.contains(touch.location(in: self)) { 
     // Your code 
    } 
} 
Cuestiones relacionadas