如何在滑动手势识别器函数中找到 UIButton 元素的父元素以构造对象?
How to find parent of a UIButton element in a swipe Gesture Recognizer function to construct an Object?
我创建了一个 'swipe to left' 函数,通过拖动按钮触发。我需要创建一个抽象 class,这样我就可以让它向左滑动触发 'swipe to function'.
的按钮的任何父元素
现在链接到该元素的父级 UIView。我尝试使用 sender.superview
但它不起作用。
@IBAction func swipeRightIncome(_ sender: Any) {
_ = UIViewPropertyAnimator(duration: 0.30, curve: .easeInOut){
self.swipeLayer.transform = CGAffineTransform(translationX: 0, y: 0)
}.startAnimation()
}
您需要将 sender 转换为 Any
类型,或者
@IBAction func swipeRightIncome(_ sender: UISwipeGestureRecognizer) {
let parent = sender.view.superView!.superView!.superView!
// do what you want
}
还要在里面声明这个ViewController
@IBOutlet weak var profitDrag:ViewDesignShadow!
我创建了一个 'swipe to left' 函数,通过拖动按钮触发。我需要创建一个抽象 class,这样我就可以让它向左滑动触发 'swipe to function'.
的按钮的任何父元素现在链接到该元素的父级 UIView。我尝试使用 sender.superview
但它不起作用。
@IBAction func swipeRightIncome(_ sender: Any) {
_ = UIViewPropertyAnimator(duration: 0.30, curve: .easeInOut){
self.swipeLayer.transform = CGAffineTransform(translationX: 0, y: 0)
}.startAnimation()
}
您需要将 sender 转换为 Any
类型,或者
@IBAction func swipeRightIncome(_ sender: UISwipeGestureRecognizer) {
let parent = sender.view.superView!.superView!.superView!
// do what you want
}
还要在里面声明这个ViewController
@IBOutlet weak var profitDrag:ViewDesignShadow!