i have a UIViewController class named as myViewClass.
there is a UIImage view named as myImageView.
how can i enable touch event on myImageView.
i used the below code to enable touch event on myImageView however the myImageView touch event is triggering on each myViewClass or UI click.
can any one tell m开发者_开发技巧e how can i avoid that.i just need only enable touch event on myImageView, when user clicks on myImageView.
i used the below code to enable touch event on myImageView:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[imageview setFrame: CGRectMake(30,70,375,225)];
[imageview.layer setBorderColor: [[UIColor whiteColor] CGColor]];
}
Using following code you can judge that your touch ended on your UIImageView.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint touchEndpoint = [touch locationInView:self.view];
if(CGRectContainsPoint([myImageView frame], touchEndpoint))
{
NSLog("Touch is in UIImageView");
}
}
In above code CGRectContainsPoint is the main function which helps to determine the touch point is in the image boundary or not.
These way you can implement in touchesBegin too. Try to implement as per your requirement. Leave a comment for further help.
Hope it helps.
精彩评论