0

这是我试图更改 imageView 大小的代码。如果您能指出任何错误,我将非常感激..

    UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ravan.jpg"]];
    imageViewForAnimation.alpha = 1.0f;
    CGSize size1=CGSizeMake(60,60);
    CGSize size2=CGSizeMake(40,40);
    CGSize size3=CGSizeMake(20,20);
    CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
    NSArray *sizeValues = [NSArray arrayWithObjects:[NSValue valueWithCGSize:size1], [NSValue valueWithCGSize:size2], [NSValue valueWithCGSize:size3], nil];
    [customFrameAnimation setValues:sizeValues];
    customFrameAnimation.duration=10.0;
    NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:1.0f], nil]; 
    [customFrameAnimation setKeyTimes:times];
    customFrameAnimation.fillMode = kCAFillModeForwards;
    customFrameAnimation.removedOnCompletion = NO;
    [imageViewForAnimation.layer addAnimation:customFrameAnimation forKey:@"customFrameAnimation"]; 
    [self.view addSubview:imageViewForAnimation]; 
4

1 回答 1

3

您正在创建一个 UIImageView,将动画附加到它,然后泄漏它。您永远不会将其附加到可见视图。你甚至不应该在屏幕上看到这个 imageview,更不用说动画了。

如果要为现有视图设置动画,则需要将动画附加到该视图,而不是创建新视图。

于 2010-01-06T15:41:57.850 回答