【问题标题】:show at the end of an image animation the last image在图像动画的末尾显示最后一张图像
【发布时间】:2014-02-27 07:06:09
【问题描述】:

首先请原谅我可能是菜鸟问题! 我是目标 C 的新手!

我想对图像进行动画处理,并且在动画结束时应该显示动画“dymchart20.png”的最后一张图像。 我该怎么做?

这是我的动画代码:

aniChartView.animationImages = [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"dymchart01.png"],
                                [UIImage imageNamed:@"dymchart02.png"],
                                [UIImage imageNamed:@"dymchart03.png"],
                                [UIImage imageNamed:@"dymchart04.png"],
                                [UIImage imageNamed:@"dymchart05.png"],
                                [UIImage imageNamed:@"dymchart06.png"],
                                [UIImage imageNamed:@"dymchart07.png"],
                                [UIImage imageNamed:@"dymchart08.png"],
                                [UIImage imageNamed:@"dymchart09.png"],
                                [UIImage imageNamed:@"dymchart10.png"],
                                [UIImage imageNamed:@"dymchart11.png"],
                                [UIImage imageNamed:@"dymchart12.png"],
                                [UIImage imageNamed:@"dymchart13.png"],
                                [UIImage imageNamed:@"dymchart14.png"],
                                [UIImage imageNamed:@"dymchart15.png"],
                                [UIImage imageNamed:@"dymchart16.png"],
                                [UIImage imageNamed:@"dymchart17.png"],
                                [UIImage imageNamed:@"dymchart18.png"],
                                [UIImage imageNamed:@"dymchart19.png"],
                                [UIImage imageNamed:@"dymchart20.png"],nil];

// all frames will execute in 3 seconds
aniChartView.animationDuration = 0.8;
// repeat the annimation forever
aniChartView.animationRepeatCount = 1;
// start animating
[aniChartView startAnimating];

谢谢你的帮助!!!

【问题讨论】:

    标签: ios animation


    【解决方案1】:

    您可以使用 NSTimer 并将您的 aniChartView 声明为您的类的属性,如下所示:

    @interface ViewController ()
    
    @property (nonatomic, strong) UIImageView *aniChartView;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)beginAnimation {
        self.aniChartView.animationImages = [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"dymchart01.png"],
                                [UIImage imageNamed:@"dymchart02.png"],
                                [UIImage imageNamed:@"dymchart03.png"],
                                [UIImage imageNamed:@"dymchart04.png"],
                                [UIImage imageNamed:@"dymchart05.png"],
                                [UIImage imageNamed:@"dymchart06.png"],
                                [UIImage imageNamed:@"dymchart07.png"],
                                [UIImage imageNamed:@"dymchart08.png"],
                                [UIImage imageNamed:@"dymchart09.png"],
                                [UIImage imageNamed:@"dymchart10.png"],
                                [UIImage imageNamed:@"dymchart11.png"],
                                [UIImage imageNamed:@"dymchart12.png"],
                                [UIImage imageNamed:@"dymchart13.png"],
                                [UIImage imageNamed:@"dymchart14.png"],
                                [UIImage imageNamed:@"dymchart15.png"],
                                [UIImage imageNamed:@"dymchart16.png"],
                                [UIImage imageNamed:@"dymchart17.png"],
                                [UIImage imageNamed:@"dymchart18.png"],
                                [UIImage imageNamed:@"dymchart19.png"],
                                [UIImage imageNamed:@"dymchart20.png"],nil];
    
        // all frames will execute in 3 seconds
        self.aniChartView.animationDuration = 0.8;
        // repeat the annimation forever
        self.aniChartView.animationRepeatCount = 1;
        // start animating
        [self.aniChartView startAnimating];
    
        [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(staticImage) userInfo:nil repeats:NO];
    
    }
    
    -(void)staticImage {
    
        [self.aniChartView stopAnimating];
        [self.aniChartView setImage:[UIImage imageNamed:@"dymchart20.png"]];
    
    }
    
    @end
    

    【讨论】:

    • 非常感谢SonGoku68!我做到了,它就像一个魅力!
    【解决方案2】:

    动画不会改变其动画元素的状态。这意味着如果您的 uiview 有背景图像,那么一旦动画停止,该图像将是相同的。 同样的事情也适用于动画的颜色变化,或者你动画的任何其他属性。 为了实现您的目标,您必须在动画结束后显式调用将 UIImage 更改为您想要看到的那个。 :)

    这是一个您可能会发现有用的解决方案https://stackoverflow.com/a/7773141/1306884

    【讨论】:

      猜你喜欢
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多