gpt4 book ai didi

iOS:如何让动画播放3次结束?

转载 作者:行者123 更新时间:2023-11-29 10:48:12 25 4
gpt4 key购买 nike

我在网上的教程中找到了这段代码。它无限循环播放动画。

我想制作一个播放三遍然后结束的动画。现在我有一个循环动画。这是一个非常简单的问题,但因为我是 iOS 的新手。

#import "APOViewController.h"

@interface APOViewController ()

@end

@implementation APOViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.png", @"win_4.png",
@"win_5.png", @"win_6.png", @"win_7.png", @"win_8.png",
@"win_9.png", @"win_10.png", @"win_11.png", @"win_12.png",
@"win_13.png", @"win_14.png", @"win_15.png", @"win_16.png"];

NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}

// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 80, 86, 193)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;

[self.view addSubview:animationImageView];
[animationImageView startAnimating];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.


}

@end

谢谢。我试图将目前收到的 2 个不同答案结合起来。但我仍然收到错误消息“'UIImageView' 没有可见的@interface 声明选择器'animationRepeatCount:'

这是我将代码更改为:

#import "APOViewController.h"
#import "UIKit/UIImageView.h"

@interface APOViewController ()
@property(nonatomic) NSInteger animationRepeatCount;

@end

@implementation APOViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.png", @"win_4.png",
@"win_5.png", @"win_6.png", @"win_7.png", @"win_8.png",
@"win_9.png", @"win_10.png", @"win_11.png", @"win_12.png",
@"win_13.png", @"win_14.png", @"win_15.png", @"win_16.png"];

NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}

// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 80, 86, 193)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;

[self.view addSubview:animationImageView];

[animationImageView startAnimating];
[animationImageView animationRepeatCount:3];
[animationImageView stopAnimating];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.


}

@end

最佳答案

这样做:

[animationImageView setRepeatCount:3];

关于iOS:如何让动画播放3次结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21612465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com