【发布时间】:2011-09-26 23:04:42
【问题描述】:
我有两个名为 image1 和 image2 的 UIImageView。我想要做的是:当 image1 和 image2 碰撞时, image1 应该变大(带有比例动画。)例如如果 image1 与 image2 碰撞十次,则 image1 应该变大 10 倍。
我尝试使用缩放动画和 CGRectIntersectsRect 进行碰撞,然后使用计时器进行碰撞,但图像只会变大一次,并且在所有后续碰撞后保持该大小。
这是我的代码:
-(void)collision {
if(CGRectIntersectsRect(imageView.frame,centre.frame)){
scale=scale+1;
imageView.alpha=0.5;
[imageView removeFromSuperview];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
centre.transform = CGAffineTransformScale(centre.transform, scale, scale);
[UIView commitAnimations];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(collision) userInfo:nil repeats:YES];
}
(TechZen 说——作者最初指出他的母语是法语,而且他的英语有点粗糙。)
【问题讨论】:
-
我从上周开始尝试这样做,所以我认为这是一个问题
-
我尝试使用缩放动画和 CGRectIntersectsRect 进行碰撞,然后使用计时器进行碰撞,但图像一次变大,然后保持相同的大小,我使用了很多东西来解决它但是没有结果,所以这就是我发布问题的原因
-
你可以在你的问题中发布一些代码吗?
-
我已经用我的代码编辑了我的帖子
-
@TechZen - 很抱歉你被耽搁了,但我真的很喜欢你的编辑。
标签: iphone xcode uiimageview collision-detection scale