[英]Swift Add UIViewController or UIView inside UITableViewCell programatically
[英]Swift - Extension UIView inside of UIViewController
我的意图是在用户尝试使用按钮而不填充所有字段的情况下使屏幕抖动。
出现以下错误:
类型'AddViewController'的值没有成员'shake'
AddViewController属于UIViewController
类,但更改扩展类也不起作用。
... else {
self.shake()
}
extension UIView {
func shake() {
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.duration = 0.6
animation.values = [-20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 ]
layer.add(animation, forKey: "shake")
}
}
您需要从vc的视图中调用它,因为扩展名是UIView
self.view.shake()
使用
self.shakeView() // directly inside the vc
做
extension UIViewController {
func shakeView() {
// .....
// here use the view
view.layer.add(animation, forKey: "shake")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.