一秒内增加和减少 imageView 的宽度

发布于 2024-12-10 12:47:09 字数 85 浏览 0 评论 0原文

所以这是我的问题: 我有一个图像“图像”,我想用动画在一秒钟内增加两倍的宽度并减少两倍的宽度。我想每秒都这样做。请问我该怎么做?抱歉我的英语我是法国人:/

So here is my question:
I have an image 'image' and I would like to increase is width of two and decrease it of two in one second with an animation. and I wanna do this every second . How can I do this please ? sorry for my english I'm french :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

美胚控场 2024-12-17 12:47:09

您好,您可以将 CoreAnimation 与 UIImageView 的 CALayer 一起使用,只需复制此代码即可。

CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulseAnimation.duration = .5;
pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulseAnimation.autoreverses = YES;
pulseAnimation.repeatCount = FLT_MAX;

UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon.png"] ];
[imgView setFrame:CGRectMake(0, 0, 50, 50)];
[self.view addSubview:imgView];
CALayer *layer = imgView.layer;
[layer addAnimation:pulseAnimation forKey:nil];

Hi you can use CoreAnimation With CALayer of UIImageView just copy past this code.

CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulseAnimation.duration = .5;
pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulseAnimation.autoreverses = YES;
pulseAnimation.repeatCount = FLT_MAX;

UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon.png"] ];
[imgView setFrame:CGRectMake(0, 0, 50, 50)];
[self.view addSubview:imgView];
CALayer *layer = imgView.layer;
[layer addAnimation:pulseAnimation forKey:nil];
说不完的你爱 2024-12-17 12:47:09
UIImage * imgOne;

imgOne.transform = CGAffineTransformMakeScale(2,1);

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
imgOne.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
UIImage * imgOne;

imgOne.transform = CGAffineTransformMakeScale(2,1);

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
imgOne.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
暖伴 2024-12-17 12:47:09

首先创建两个具有图像原始视图值的浮点,例如 float1 和 float2。

image.imageView.bounds.size.width = float1;
image.imageView.bounds.size.height = float2;

然后,创建一个名为 x 的整数,并在 ccTime 函数中每次将 x 加一(这将导致 x 每秒被调用 60 次),所以现在您可以设置如下语句...

if(x > 60){
float1 = float1 + (how much bigger you want the image to be)
float2 = float2 + (how much bigger you want the image to be)
}

如果您提供了一些示例代码,我本来能够更好地回答你的问题:/

如果你不使用cocos2d,那么你将不得不使用NSTimer而不是ccTime。

Well start by creating two floats that have the value of the original view of the image, lets say float1 and float2.

image.imageView.bounds.size.width = float1;
image.imageView.bounds.size.height = float2;

Then, create an integer called x, and inside your ccTime function increment x by one every time(this will cause x to be called 60 times a second) so now you can set up statements like...

if(x > 60){
float1 = float1 + (how much bigger you want the image to be)
float2 = float2 + (how much bigger you want the image to be)
}

If you would have provided some example code, I would have been able to answer your question better :/

And if your not using cocos2d, then you will have to use NSTimer instead of ccTime.

温柔少女心 2024-12-17 12:47:09
  1. 将其放入动画块中
  2. 使用选择器

    - (void)startSizeChange {
        [UIView beginAnimations:@"changeSize" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDidStopSelector:@selector(endSizeChange)];
        [UIView setAnimationDuration:0.5];
        imageview.frame.size.height = 100;
        [UIView提交动画]; 
     }
    
    - (void)endSizeChange {
    
        [UIView beginAnimations:@"changeSize" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDidStopSelector:@selector(startSizeChange)];
        [UIView setAnimationDuration:0.5];
        imageview.frame.size.height = 50;
        [UIView提交动画]; 
     }
    
  1. Put it in an animation block
  2. Use a selector

    - (void)startSizeChange {
        [UIView beginAnimations:@"changeSize" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDidStopSelector:@selector(endSizeChange)];
        [UIView setAnimationDuration:0.5];
        imageview.frame.size.height = 100;
        [UIView commitAnimations]; 
     }
    
    - (void)endSizeChange {
    
        [UIView beginAnimations:@"changeSize" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDidStopSelector:@selector(startSizeChange)];
        [UIView setAnimationDuration:0.5];
        imageview.frame.size.height = 50;
        [UIView commitAnimations]; 
     }
    
岁吢 2024-12-17 12:47:09

试试这个:

- (void)startSizeChange {

    [UIView beginAnimations:@"changeSize" context:nil];
    [UIView setAnimationCurve:
    [UIView setAnimationDuration:0.3];
    YourImageView.frame = CGRect(YourImageView x + 10 , YourImageView y + 10, YourImageView weight - 10, YourImageView height - 10);
    [UIView commitAnimations]; 

    [self endSizeChange];
 }

- (void)endSizeChange {

    [UIView beginAnimations:@"changeSize" context:nil];
    [UIView setAnimationCurve:
    [UIView setAnimationDuration:0.3];
    YourImageView.frame = CGRect(YourImageView x - 10 , YourImageView y - 10, YourImageView weight + 10, YourImageView height + 10);
    [UIView commitAnimations]; 
 }

Try this:

- (void)startSizeChange {

    [UIView beginAnimations:@"changeSize" context:nil];
    [UIView setAnimationCurve:
    [UIView setAnimationDuration:0.3];
    YourImageView.frame = CGRect(YourImageView x + 10 , YourImageView y + 10, YourImageView weight - 10, YourImageView height - 10);
    [UIView commitAnimations]; 

    [self endSizeChange];
 }

- (void)endSizeChange {

    [UIView beginAnimations:@"changeSize" context:nil];
    [UIView setAnimationCurve:
    [UIView setAnimationDuration:0.3];
    YourImageView.frame = CGRect(YourImageView x - 10 , YourImageView y - 10, YourImageView weight + 10, YourImageView height + 10);
    [UIView commitAnimations]; 
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文