2011-03-04 14 views

Odpowiedz

8

mam odpowiedzieć sobie ... ale dzięki inne, które pomogły mi w tym

tutaj jest

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


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

Należy utworzyć podklasę (lub utworzyć kategorię) UIView i zastąpić

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

gdzie przekierować wiadomość do odpowiedniego delegata.

+0

no nie musisz tego robić ... sprawdź moje własne odpowiedzi, które znalazłem tylko kilka minut temu ... –

+0

Wygląda na to, że źle zrozumiałem twoje pytanie. – Max

+0

+1 .. dobrze na przemian, jeśli duże prace do zrobienia na wydziale, dzięki –

0

Czy u spróbować

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

nie daje to lokalizacji w widoku, a nie widok, który został dotknięty .... –

7

Spróbuj

//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 dobra odpowiedź, ale proszę również sprawdzić mój. ... –

+0

Ya..to zbyt dobrze. + 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); 
    } 
} 

jak to można znaleźć widoku lub podrzędny dotknięciu

1

Herezje swift3 wersja bez multitouch:

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