4

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

有人可以给我一些建议吗?

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

谢谢你 :)

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

行动

//显示你的警报...

NSLog(@"tapped");

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

//推送到花卉细节视图

4

3 回答 3

5

我会在图像视图之上添加一个透明视图,并为其添加一个手势识别器。

于 2011-12-01T11:10:51.860 回答
3

这是因为在应用动画时,动画对精灵(在你的情况下为 UIImageView)的任何值的修改都不会应用到精灵原始,而是应用到它的 .layer.presentationLayer,真正的仍然在它的原来的地方。在这种情况下,你可以试试这个:把你的手势放在整个屏幕上,当响应来自事件时,你检查触摸点,对presentationLayer进行hitTest,如果是,那么做你想做的事。

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

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

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

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
于 2011-12-01T13:13:49.547 回答
1

真的很晚了,但我一直面临同样的问题,我发现了我认为更好的解决方案:

只需像这样使用 UIViewAnimationOptionAllowUserInteraction 选项:

[UIView animateWithDuration:4.0
                      delay:0
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^{ 
                     imageViewTop.alpha = 0.0;
                     imageViewBottom.alpha = 1.0;
                 } 
                 completion:^(BOOL  completed){
                     [self nextAnimation:stringsize.width];
                 }
];
于 2015-06-18T10:55:03.213 回答