如何在 UIImageView 动画时检测触摸
我有一个 UIImageview 从一个位置移动到另一个位置。当我尝试在动画期间点击图像时,不会调用触摸事件委托方法。但是当我在动画完成后点击图像时,委托方法就会执行。当 uiimageview 改变其位置时,如何检测它的触摸事件。
我的代码:
vwb2 = [[UIView alloc] initWithFrame:CGRectMake(240, 500, 50, 50)];
[self.view addSubview:vwb2];
ballon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"b2.png"]];
ballon2.userInteractionEnabled = TRUE;
ballon2.frame = CGRectMake(0, 0, 50, 50);
[vwb2 addSubview:ballon2];
[ballon2 release];
编辑:
我的动画代码:
[UIView animateWithDuration:2.0
animations:^{
vwb1.center = CGPointMake(260, 40);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.5
animations:^{
vwb2.center = CGPointMake(260, 100);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
vwb3.center = CGPointMake(260, 160);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
vwb4.center = CGPointMake(260, 220);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0 animations:^{
vwb5.center = CGPointMake(260, 280);
} ];
}];
}];
}
];
}];
谢谢
潘卡伊
I have an UIImageview which moves from a position to another. When I try to tap on the image during the animation touch event delegate method is not called. But when I tap on image after the completion of the animation, the delegate method executes. How can I detect the touch event on the uiimageview while it is changing its position.
my code:
vwb2 = [[UIView alloc] initWithFrame:CGRectMake(240, 500, 50, 50)];
[self.view addSubview:vwb2];
ballon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"b2.png"]];
ballon2.userInteractionEnabled = TRUE;
ballon2.frame = CGRectMake(0, 0, 50, 50);
[vwb2 addSubview:ballon2];
[ballon2 release];
Edit:
My code for animation:
[UIView animateWithDuration:2.0
animations:^{
vwb1.center = CGPointMake(260, 40);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.5
animations:^{
vwb2.center = CGPointMake(260, 100);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
vwb3.center = CGPointMake(260, 160);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
vwb4.center = CGPointMake(260, 220);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0 animations:^{
vwb5.center = CGPointMake(260, 280);
} ];
}];
}];
}
];
}];
Thanks
Pankaj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获取位置...
并在touchesEnded方法中检查CGRectContainsPoint([self getPos],touchPoint)
(我的旧答案)
You can get position...
And check CGRectContainsPoint([self getPos],touchPoint) in touchesEnded method
(My old answer)
在我的项目中,我没有检测到UIImageView的任何触摸事件。
我检测到父视图的触摸事件,并使用触摸点和 UIImageView 的矩形来检测 UIImageView 被触摸。
也许你可以尝试一下。
In my project, I did not detect any touch event of UIImageView.
I detected touch event of parent view and used touch point and UIImageView's rect to detect the UIImageView was touched.
Maybe you can try it.
我已发布正确的解决方案作为对我原始问题的编辑
I have posted correct solution as edit to my original question