【发布时间】:2015-11-11 20:26:26
【问题描述】:
我一直试图让这段代码工作,但我似乎无法让我的 UIButton 通过图像进行动画处理。
@IBOutlet weak var screenButton: UIButton!;
func animation(){
var animationButton : UIButton!;
var imageList = [UIImage]();
var image1:UIImage = UIImage(named:"3fingers-o-l-animation1.png")!;
var image2:UIImage = UIImage(named:"4fingers-o-l-animation1.png")!;
animationButtonscreenButton = screenButton;
imageList = [image1, image2];
animationButton!.imageView!.animationImages = imageList;
animationButton!.imageView!.animationDuration = 1.0;
animationButton!.imageView!.startAnimating();
}
编写此代码后,我将一条线从 screenButton 拖到我想要通过 Storyboard 中的图像制作动画的按钮。 我究竟做错了什么?
【问题讨论】:
-
UIButton 未初始化...
-
这就是为什么你应该在适当的时候使用
?和!。不要?所有代码,因为它会隐藏错误。如果应该存在某些东西,请使用强制解包!。或者在这种情况下只是一个非可选变量。你会很早就看到这个问题。 -
i) 初始化 UIButton ii) 设置它的框架 iii) addSubview 在你的视图上
-
我已经尝试了您的建议,但仍然无法正常工作。我已经用我所做的事情编辑了我的问题。
标签: ios swift animation uibutton