开发者

problem with scaling a uiimageView after a collision

开发者 https://www.devze.com 2023-03-17 22:03 出处:网络
he开发者_JAVA百科re is my code: - (void) yo { if(CGRectIntersectsRect(imageView.frame,centre.frame)){

he开发者_JAVA百科re is my code:

- (void) yo { 
if(CGRectIntersectsRect(imageView.frame,centre.frame)){

    [imageView removeFromSuperview];
self.scale=self.scale+1; 

[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];

scale=1;

}

I want to scale +1 "centre" every time it collide with "imageView"(thus it become bigger and bigger) but when it collide just one time, "centre" become very big, I think it is due to the timer. How can I solve this please ? sorry for my english I'm french :/


change this

self.scale=self.scale+0.01; or custom value

self.scale=self.scale+0.5;

this is for half of scale will be added so 1.5 times bigger 1.0 is normal


centre.transform already has the scale factor applied. No need to keep track of it yourself.

If you intend to increase centre's size by 10% each time, do this,

centre.transform = CGAffineTransformScale(centre.transform, 1.1, 1.1);

This will add to the existing scale. If you find this to be big, reduce the amount by which you are scaling, say 1.02 or 1.002 for example.

If you intend to maintain your own scale, you can do

centre.transform = CGAffineTransformMakeScale(scale, scale);

You are also increasing the scale factor by 1 each time. This is really a huge factor. A scale factor of 2 will double the size of the image and 2 will triple. And since you have a pretty short interval to test the collision, you might have to look at a smaller scale factor.

0

精彩评论

暂无评论...
验证码 换一张
取 消