如何使动画识别器在动画UIImage视图中工作 [英] how to to make gesturerecognizer working in an animating UIImage view

查看:65
本文介绍了如何使动画识别器在动画UIImage视图中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图像视图中有5个动画图像,并希望允许用户根据默认ID点击它们并将其推送到另一个视图。我试图添加手势点击,但imageview没有检测到。

i have 5 animating image in a image view and will like to allow user to tap on them base on the default ID and push it to another view. i tried to add in gesture tap but the imageview are not detecting.

任何人都可以给我一些建议吗?

can anybody give me some advise ?

编辑:最后我没有使用它,我设置了一个UIButton。

end up i did not use it, i set a UIButton instead.

谢谢你:))

viewDidLoad

viewDidLoad

self.defaultID = [[NSMutableArray alloc] initWithObjects:@"7",@"9",@"11",@"27",@"6",nil];
self.defaultImageCaption = [[NSMutableArray alloc] initWithObjects:@"Ver",@"Green",@"Red",@"CF",@"Dwarf",nil];

//default image
imageViewTop.alpha = 1.0;
imageViewBottom.alpha = 0.0;
imageViewBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)];
imageViewTop = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)];

singleDefaultTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDefaultTap:)];
singleDefaultTap.numberOfTouchesRequired = 1;
imageViewTop.userInteractionEnabled = YES;
[imageViewTop addGestureRecognizer:singleDefaultTap];
imageViewTop.tag = 2000;

UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,44,320,367)];
[topView addSubview:imageViewTop];
[self.view addSubview:imageViewTop];
[self.view addSubview:topView];
[self.view addSubview:imageViewBottom];

[self nextAnimation]







-(void)nextAnimation{

//picture loop
imageViewTop.image = imageViewBottom.image;
imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1];

[imageArray insertObject:imageViewBottom.image atIndex:0];
[imageArray removeLastObject];
imageViewTop.alpha = 1.0;
imageViewBottom.alpha = 0.0;

[UIView animateWithDuration:4.0
                 animations:^{ 
                     imageViewTop.alpha = 0.0;
                     imageViewBottom.alpha = 1.0;
                     } 
                 completion:^(BOOL  completed){
                     [self nextAnimation:stringsize.width];
                 }
 ]; 






行动


action

//显示您的提醒...

//show your alert...

NSLog(@"tapped");

flowerDetails = [[FlowerDetailViewController alloc] initWithNibName:@"FlowerDetailViewController" bundle:Nil] ;
Fr *fr = nil;

//推送到花卉详情视图

//push to flower detail view

推荐答案

这是因为当动画应用时,动画中任何精灵值(在你的情况下是UIImageView)的修改都不会应用于精灵原始,它会应用于它。 layer.presentationLayer,真实的仍然在原来的位置。在这种情况下,您可以尝试这样做:将您的手势放在整个屏幕上,当响应来自事件时,您检查触摸点,对presentationLayer进行hitTest,如果是,则执行您想要的操作。

It is because that when animation is applying, the modification for any value of the sprite(UIImageView in your case) by animation is not applied to the sprite original, it is applied to its .layer.presentationLayer, the real one is still at its original place. In this case, you can try this: Put your gesture on the whole screen, when response comes from event, you check the touch point, make a hitTest to the presentationLayer, if yes then do what you want.

我通常使用下面的代码来做到这一点。

I usually use below code to do that.

- ( BOOL ) areYouThere: ( CGPoint ) point {
    return ( [ ( ( CALayer * )sprite.layer.presentationLayer ) hitTest: point ] != nil );
}

调用以下方法时从UITouch对象获取触摸点

Get the touch point from a UITouch object when below method is invoked

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

这篇关于如何使动画识别器在动画UIImage视图中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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