动画图像数组的问题

发布于 2024-11-27 14:11:17 字数 883 浏览 2 评论 0原文

这是我的代码:

-(void) createNewImage {

image.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"oeufgrisé.png"],
                         [UIImage imageNamed:@"abouffer_03.png"],
                         [UIImage imageNamed:@"boutonplay_03.png"],
                         [UIImage imageNamed:@"boutonpause_03.png"],
                         [UIImage imageNamed:@"abouffer_05.png"],
                         [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
[image setAnimationRepeatCount:10];
image.animationDuration =1.5;
[image startAnimating];      

imageView = [[UIImageView alloc] initWithImage:image];

}

该代码不起作用,我不知道为什么。我总是在“imageView = [[UIImageView alloc] initWithImage:image];”行上出现此警告:从不同的 Objective C 类型传递 initWithImage 的参数 1 时,不兼容的 ObjectiveC 类型 struct UIImageView*' 预期的 struct UIImage*'

here is my code :

-(void) createNewImage {

image.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"oeufgrisé.png"],
                         [UIImage imageNamed:@"abouffer_03.png"],
                         [UIImage imageNamed:@"boutonplay_03.png"],
                         [UIImage imageNamed:@"boutonpause_03.png"],
                         [UIImage imageNamed:@"abouffer_05.png"],
                         [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
[image setAnimationRepeatCount:10];
image.animationDuration =1.5;
[image startAnimating];      

imageView = [[UIImageView alloc] initWithImage:image];

}

This code doesn't work, I don't know why. I have always this warning on line "imageView = [[UIImageView alloc] initWithImage:image];" :Incompatible ObjectiveC type struct UIImageView*' expected struct UIImage*' when passing argument 1 of initWithImage from distinct Objective C type

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

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

发布评论

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

评论(3

不爱素颜 2024-12-04 14:11:17

您可以将动画图像设置为 UIImageView ,而不是 UIImage 。

-(void) createNewImage {
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];

    imageView.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"oeufgrisé.png"],
                             [UIImage imageNamed:@"abouffer_03.png"],
                             [UIImage imageNamed:@"boutonplay_03.png"],
                             [UIImage imageNamed:@"boutonpause_03.png"],
                             [UIImage imageNamed:@"abouffer_05.png"],
                             [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
    [imageView setAnimationRepeatCount:10];
    imageView.animationDuration =1.5;
    [imageView startAnimating]; 
    [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(setLastImage:) userInfo:nil repeats:NO];

 }

-(void)setLastImage:(id)obj
{
    [imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"mangeurcentremieu3_03.png"] waitUntilDone:YES];
}

You can set animation images to UIImageView , and not to UIImage.

-(void) createNewImage {
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];

    imageView.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"oeufgrisé.png"],
                             [UIImage imageNamed:@"abouffer_03.png"],
                             [UIImage imageNamed:@"boutonplay_03.png"],
                             [UIImage imageNamed:@"boutonpause_03.png"],
                             [UIImage imageNamed:@"abouffer_05.png"],
                             [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
    [imageView setAnimationRepeatCount:10];
    imageView.animationDuration =1.5;
    [imageView startAnimating]; 
    [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(setLastImage:) userInfo:nil repeats:NO];

 }

-(void)setLastImage:(id)obj
{
    [imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"mangeurcentremieu3_03.png"] waitUntilDone:YES];
}
不必了 2024-12-04 14:11:17

如果您正在这样做:

image.animationImages = [NSArray arrayWithObjects:

那么 image 是一个 UIImageView (查看分配它的代码)。这就是您收到错误的原因,因为 initWithImage 需要 UIImage 类型的对象:

- (id)initWithImage:(UIImage *)image

要么您并不意味着 image 是图像视图,或者可能您不'不需要在您的方法中分配第二个 UIImageView,只需使用 image 即可。

If you are doing:

image.animationImages = [NSArray arrayWithObjects:

then image is an UIImageView (review the code where you allocate it). That is the reason why you get the error, since initWithImage expects an object of type UIImage:

- (id)initWithImage:(UIImage *)image

Either you did not mean image to be an image view, or possibly you don't need to allocate a second UIImageView in your method and can just use image.

愛放△進行李 2024-12-04 14:11:17

确保 image 是 UIImageView 而不是 UIImage。您只能为 UIImageView 创建动画图像。

Make sure that image is a UIImageView and not a UIImage. You can only create animationImages for UIImageViews.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文