简体   繁体   中英

facing issue for touch down event for UIImageView again

If My Story Board contains

   View      
     |_my UIIMageView 1 
     |
     |_my UIImageView 2

I can handle the touch down event by following the solution at this post

However, if my Story Board is changed to

   Scroll View      
     |_my UIIMageView 1 
     |
     |_my UIImageView 2

Now I can not detect the touch down event on one of these UIImageView... Please help me on this issue..

Probably not the answer you're looking for, but you should think about using UIButtons instead of UIImageViews.

Each UIButton have an UIImageView inside plus all the touch events with it.

I have used :

    UITapGestureRecognizer *touch;

    UIImageView *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
    anImageView.image = [UIImage imageNamed:@"iad.png"];
    [anImageView setUserInteractionEnabled:TRUE];
    anImageView.tag = 1001 ;

    touch = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)] autorelease];
    touch.numberOfTapsRequired = 1;
    [anImageView addGestureRecognizer:touch];
    [scrollView addSubview:anImageView];
    [anImageView release];

- (void) test:(UIGestureRecognizer *)sender
{

     UIImageView *imageView = (UIImageView *)sender.view;

     switch (imageView.tag)
     {
        case 1001: 
         // your code
        break;

        case 1002:
         // your code
         break;
      }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM