动画图像数组的问题
这是我的代码:
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将动画图像设置为 UIImageView ,而不是 UIImage 。
You can set animation images to UIImageView , and not to UIImage.
如果您正在这样做:
那么
image
是一个UIImageView
(查看分配它的代码)。这就是您收到错误的原因,因为initWithImage
需要 UIImage 类型的对象:要么您并不意味着
image
是图像视图,或者可能您不'不需要在您的方法中分配第二个 UIImageView,只需使用image
即可。If you are doing:
then
image
is anUIImageView
(review the code where you allocate it). That is the reason why you get the error, sinceinitWithImage
expects an object of type UIImage: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 useimage
.确保
image
是 UIImageView 而不是 UIImage。您只能为 UIImageView 创建动画图像。Make sure that
image
is a UIImageView and not a UIImage. You can only create animationImages for UIImageViews.