【发布时间】:2017-03-18 19:19:58
【问题描述】:
我想在我的自定义视图上使用 Appearable 协议中的方法。
protocol Appearable { }
extension Appearable where Self: UIView {
func appear(duration: Double, delay: Double) {
self.alpha = 0
UIView.animate(withDuration: duration, delay: delay, options: .curveEaseIn, animations: {
self.alpha = 1
self.transform = CGAffineTransform(scaleX: 2.0, y: 1.5)
}, completion: nil)
self.transform = CGAffineTransform.identity
}
}
我的自定义视图:
class CustomView: UIView, Appearable {}
在我的 MainView 中,我创建了一个带有我想在屏幕上显示的图像的变量。
class MainView: UIView {
let randomView: CustomUIView = {
var image = CustomUIView()
image = UIImageView(image: myImage)
return image
}
此代码将不起作用,因为无法将“UIImageView”类型的值分配给“CustomView”类型。我的问题是,进行这种操作的正确方法是什么。
【问题讨论】:
标签: ios swift uiview uiimageview