【发布时间】:2011-05-08 08:14:25
【问题描述】:
这是我的问题: 我有两个图像:flakeImage 和 ViewToRotate。我想要的是,如果 flakeImage 触及 ViewToRotate,ViewToRotate.alpha=0.5;但是当 FlakeImage 出现在屏幕上时 ViewToRotate.alpha=0.5;不碰它。我认为这是我的观点有问题,因为我有:
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
这里是代码:
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
// use the random() function to randomize up our flake attributes
int startY = round(random() % 320);
// set the flake start position
flakeView.center = CGPointMake(490, startY);
flakeView.alpha = 1;
// put the flake in our main view
[self.view addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
// set up how fast the flake will fall
[UIView setAnimationDuration:7 ];
// set the postion where flake will move to
flakeView.center = viewToRotate.center;
// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
请问我该如何解决? 如果有人可以帮助我,那就太好了。
【问题讨论】:
-
在动画结束时将 alpha 设置为 0.5 就足够了吗?还是需要真正的碰撞代码?
-
我需要真正的碰撞代码但是当图像(flakeView)出现在屏幕上而不碰撞另一个时是.alpha=0.5;
-
嗯,我仍然不确定您真正需要什么。所以你有一片片,也许是一片雪片?它从一个随机高度(startY)开始下降,或者很好地到达 viewToRotate 所在的位置,对吧?那么,当动画的目标是让薄片处于另一个视图的相同位置时,为什么需要碰撞检测呢?到目前为止,它是关于位置的,alpha 与它有什么关系?当薄片到达最终目的地时,它应该变成半透明吗?请帮我理解。
-
不,因为 viewToRotate 是一个男人的头,我想要的是薄片接触嘴巴,因为动画使薄片到达头部的中心,直到它才停止已经到达中心。我想要的只是:如果碰撞 viewToRotate 和剥落(做某事)。我该怎么做。请帮帮我
-
@arvin - 这不是 Stack Overflow 的工作方式。如果您对原始问题没有得到很好的答复,请对其进行编辑以使问题更清晰。转发问题是不可接受的,无论这对您来说多么紧急。
标签: iphone cocoa-touch animation uiimageview collision-detection