views:

12

answers:

1

In below code how can i understand that which control touched?(imagine that exist button1,label1,.. on view)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

}
A: 

Check the view property on the touch object. From the documentation:

The value of the property is the view object in which the touch originally occurred.

Robot K
i use if([touch view]==button1) but doesn't work
What's the output of `NSLog(@"touch.view: %@", touch.view);`?
Robot K
touch.view: <UIView: 0x592ed60; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x592ede0>>
From the Run menu in Xcode, choose Debug. Once the app is running, go back to Xcode and choose Console from the Run menu.
Robot K
Do you have userInteractionEnabled set to YES on your subviews? https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/userInteractionEnabled
Robot K