UIImageView触摸事件 [英] UIImageView Touch Event

查看:137
本文介绍了UIImageView触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在触摸名为(image1)的uiimageview时调用我的按钮点击事件.Imageview放在uiview(view1)中。

I want to call my button click event while touching the uiimageview named as(image1).Imageview placed in uiview(view1).

这是我的代码:

- (IBAction)buttonClicked:(id)sender
{

 myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(alphabutt:) userInfo:nil repeats:NO];
 }


-(IBAction)alphabutt:(id)sender
{
 NSLog(@"alphabutt!");


 if(i==1)
 {
  NSLog(@"i==1");
  [image1 setImage:[UIImage imageNamed:@"appleimg.jpg"]];
  [view1 addSubview:image1];  
  transition1 = [CATransition animation];

  transition1.duration = 0.75;

  transition1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

  transition1.type=kCATransitionReveal;
  transition1.subtype=kCATransitionFromRight;
  transitioning = YES;
  transition1.delegate = self;
  [image1.layer addAnimation:transition1 forKey:nil];  
 }
 if(i==2)
 {
  NSLog(@"i==2");
  [image1 setImage:[UIImage imageNamed:@"boatimg.jpg"]];
  [view1 addSubview:image1];  
  transition2 = [CATransition animation];

  transition2.duration = 0.75;

  transition2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

  transition2.type=kCATransitionFade;
  transition2.subtype=kCATransitionFromRight;
  transitioning = YES;
  transition2.delegate = self;
  [image1.layer addAnimation:transition2 forKey:nil];

  i=0;
 }
i++;

}

上面是我的代码,同时点击按钮点击按钮的事件调用.Inide buttonclick事件定时器正在调用alphabutt(按钮点击事件),时间间隔为2.0.alphabutt每2.0调用一次。我想在触摸uiimageview(image1)时执行此动画只有它调用按钮点击事件(alphabutt)。
如何为imageview编写触摸事件...

The above is my code while clicking the button the buttonclicked event is called.Inside buttonclick event the timer is working to call the alphabutt(Button click event)with the time interval of 2.0.alphabutt is called with every 2.0.I want to do this animation when i'm touch the uiimageview(image1) then only it calls the button click event (alphabutt). how can I write the touch event for imageview...

请简要说明一些代码来执行uiimageview触摸事件......

Please explain briefly with some code to perform uiimageview touch event...

推荐答案

你可以使用 UITapGestureRecognizer 添加到 UIImageView 通过 addGestureRecognizer

you can use UITapGestureRecognizer added to the UIImageView via addGestureRecognizer

片段:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bannerTapped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[iv addGestureRecognizer:singleTap];
[iv setUserInteractionEnabled:YES];

- (void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"%@", [gestureRecognizer view]);
}

这篇关于UIImageView触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆