Search code examples
iphoneobjective-ciosuitouchuiwindow

touch events on UIimageView which is on UIwindow


I m using UIimageview on top of UIWindow. I want to handle touch event for that Imageview, but m not able to do it.

When i use UIimageView on UIview, we can use touchBegan, touchEnded but how to handle it when it is on UIWindow instead of UIView.

Thanks..


Solution

  • If you just want to handle the tap, you have to set,

    imageView.userInteractionEnabled = YES;
    

    By default UIImageView has the userInteractionEnabled property set to NO. And you can add a tap gesture recognizer to it,

    UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(anyMethod)];
    [imageView addGestureRecognizer:tgr];
    [tgr release];
    

    If you want to move the image, you can use UIPanGestureRecognizer.