gpt4 book ai didi

iphone - UIImageView触摸事件

转载 作者:行者123 更新时间:2023-12-03 18:14:07 25 4
gpt4 key购买 nike

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

这是我的代码:

- (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++;

}

上面是我的代码,当单击按钮时,将调用buttonclicked事件。在buttonclick事件内,计时器正在以2.0的时间间隔调用alphabutt(按钮单击事件)。每隔2.0调用一次alphabutt。我想要当我触摸 uiimageview(image1) 时执行此动画,然后只有它调用按钮单击事件(alphabutt)。我怎样才能为imageview编写触摸事件...

请简要解释一些执行 uiimageview 触摸事件的代码...

最佳答案

您可以使用通过addGestureRecognizer添加到UIImageViewUITapGestureRecognizer

片段:

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]);
}

关于iphone - UIImageView触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3775577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com