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

时间:2011-10-14 17:20:50

标签: iphone xcode animation timer width

所以这是我的问题:  我有一个图像'图像',我想增加宽度为2,并在一秒钟内用动画减少两个。我想每一秒都这样做。我该怎么办?对不起我的英语我是法国人:/

5 个答案:

答案 0 :(得分:1)

您好,您可以使用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];

答案 1 :(得分:0)

UIImage * imgOne;

imgOne.transform = CGAffineTransformMakeScale(2,1);

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

答案 2 :(得分:0)

首先创建两个具有图像原始视图值的浮点数,比如说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。

答案 3 :(得分:0)

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

答案 4 :(得分:0)

试试这个:

- (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]; 
 }