Objective c 应能识别点击的动画UIImageView(在UIImageView所在的每个位置)
我正在制作一个iPhone应用程序,其中包括从屏幕底部生成气球(UIImageView)并向上移动到屏幕顶部 其目的是设置UIImageViews,以便气球上的点击手势可以将气球从屏幕上移除 我已经设置了手势识别器,正在识别水龙头 我遇到的问题是,我使用的动画方法没有提供有关在特定时间点绘制气球的位置的信息,而是将气球视为已到达所提到的最后一点 这会导致只在屏幕顶部(气球的最终目的地)识别点击的问题 我已将动画代码粘贴到此处:Objective c 应能识别点击的动画UIImageView(在UIImageView所在的每个位置),objective-c,animation,uiimageview,state,uigesturerecognizer,Objective C,Animation,Uiimageview,State,Uigesturerecognizer,我正在制作一个iPhone应用程序,其中包括从屏幕底部生成气球(UIImageView)并向上移动到屏幕顶部 其目的是设置UIImageViews,以便气球上的点击手势可以将气球从屏幕上移除 我已经设置了手势识别器,正在识别水龙头 我遇到的问题是,我使用的动画方法没有提供有关在特定时间点绘制气球的位置的信息,而是将气球视为已到达所提到的最后一点 这会导致只在屏幕顶部(气球的最终目的地)识别点击的问题 我已将动画代码粘贴到此处: UIViewAnimationOptions options = U
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:2.0 delay:0.0 options:options animations:^{
balloonImageView.center = p;
} completion:^(BOOL finished) {
if (finished) {
balloonImageView.hidden= TRUE;
balloonImageView.image=nil;
}
我通过为UIImageView提供一个唯一的标记,并检查signature.view.tag=anyBalloodObject.tag是否存在,以及是否存在,来跟踪图像的位置,并销毁气球
我的基本问题是,还有其他动画工具可以使用吗?我知道我可以将气球的终点设置为比屏幕上的稍高一点,直到它到达顶部,但这似乎对记忆来说非常费力。
你有什么建议吗?我查阅了核心动画参考资料,没有找到任何适合我需要的方法
此外,UIViewAnimation的多线程方面是否会影响tap系统的准确性
谢谢,
Vik你不应该像那样设置游戏对象(移动时与之交互的对象)的动画。 您应该使用NSTimer来移动气球
-(void)viewDidLoad {
//Set up a timer to run the update-function
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:NULL repeats:YES];
}
-(void) update {
for (int i = [balloonArray count] - 1; i >= 0; i--) { //Loop through an array containing all your balloons.
UIImageView *aBalloon = [balloonArray objectAtIndex:i]; //Select balloon at the current loop index
aBallon.center = CGPointMake(aBallon.center.x, aBalloon.center.y + 1); //Change the center of that balloon, in this case: make it go upwards.
}
}
以下是您需要在.h中声明的内容:
NSTimer *timer;
NSMutableArray *ballonArray;
//You should use properties on these also..
您必须创建一个spawn方法,将引出序号添加到屏幕和数组中。
完成此操作后,触摸方法的实现非常简单,您只需在气球中循环并检查:
//You need an excact copy of the loop from earlier around this if statement!
If (CGRectContainsPoint(aBalloon.frame, touchlocation)) { //you can do your own tap detection here inthe if-statement
//pop the balloon and remove it from the array!
}
希望这看起来不太吓人,祝你好运。你不应该像那样设置游戏对象(移动时与之交互的对象)的动画。 您应该使用NSTimer来移动气球
-(void)viewDidLoad {
//Set up a timer to run the update-function
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:NULL repeats:YES];
}
-(void) update {
for (int i = [balloonArray count] - 1; i >= 0; i--) { //Loop through an array containing all your balloons.
UIImageView *aBalloon = [balloonArray objectAtIndex:i]; //Select balloon at the current loop index
aBallon.center = CGPointMake(aBallon.center.x, aBalloon.center.y + 1); //Change the center of that balloon, in this case: make it go upwards.
}
}
以下是您需要在.h中声明的内容:
NSTimer *timer;
NSMutableArray *ballonArray;
//You should use properties on these also..
您必须创建一个spawn方法,将引出序号添加到屏幕和数组中。
完成此操作后,触摸方法的实现非常简单,您只需在气球中循环并检查:
//You need an excact copy of the loop from earlier around this if statement!
If (CGRectContainsPoint(aBalloon.frame, touchlocation)) { //you can do your own tap detection here inthe if-statement
//pop the balloon and remove it from the array!
}
希望这看起来不太吓人,祝你好运。谢谢。。看起来一点也不可怕。。我试过类似的方法,但我不知道如何编码的部分是触摸手势。。CGRectContainsPoint方法。无论如何它按我所期望的方式工作。。你应该解释为什么他的方法无效,为什么你的方法更好谢谢。。看起来一点也不可怕。。我试过类似的方法,但我不知道如何编码的部分是触摸手势。。CGRectContainsPoint方法。无论如何它按我所期望的方式工作。。你应该解释为什么他的方法无效,为什么你的方法更好