[英]how to to make gesturerecognizer working in an animating UIImage view
我在圖像視圖中有5個動畫圖像,並希望允許用戶根據默認ID點擊它們並將其推送到另一個視圖。 我試圖添加手勢點擊,但imageview沒有檢測到。
任何人都可以給我一些建議嗎?
編輯:最后我沒有使用它,我設置了一個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;
//推到花卉細節視圖
我會在圖像視圖的頂部添加透明視圖,並為其添加手勢識別器。
這是因為當應用動畫時,動畫中任何精靈值(在你的情況下是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
真的很晚但我一直面臨同樣的問題,我發現我認為是更好的解決方案:
只需使用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];
}
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.