我已創建自定義按鈕類並覆蓋所有觸摸方法。它適用於swift 2
和Xcode 7.3.1
。但是,當我在Xcode 8.0
打開相同的應用程序,它會顯示錯誤:'CustomButton'類型的值沒有成員'touchDown'
類型的值「的CustomButton」沒有成員「着陸」
類型的值「的CustomButton」沒有成員「touchUpInside」
值類型「的CustomButton」的沒有成員「touchDragExit」
類型的值「的CustomButton」沒有成員「touchDragEnter」
類型自定義的「價值按鈕」沒有成員‘touchCancel’
這裏是我的代碼:
import UIKit
@IBDesignable
@objc public class CustomButton: UIButton {
private func addTargets() {
//------ add target -------
self.addTarget(self, action: #selector(self.touchDown(_:)), for: UIControlEvents.TouchDown)
self.addTarget(self, action: #selector(self.touchUpInside(_:)), for: UIControlEvents.TouchUpInside)
self.addTarget(self, action: #selector(self.touchDragExit(_:)), for: UIControlEvents.TouchDragExit)
self.addTarget(self, action: #selector(self.touchDragEnter(_:)), for: UIControlEvents.TouchDragEnter)
self.addTarget(self, action: #selector(self.touchCancel(_:)), for: UIControlEvents.TouchCancel)
}
func touchDown(sender: CustomButton) {
self.layer.opacity = 0.4
}
func touchUpInside(sender: CustomButton) {
self.layer.opacity = 1.0
}
func touchDragExit(sender: CustomButton) {
self.layer.opacity = 1.0
}
func touchDragEnter(sender: CustomButton) {
self.layer.opacity = 0.4
}
func touchCancel(sender: CustomButton) {
self.layer.opacity = 1.0
}
}
如果任何人有任何解決方案,請讓我知道。
感謝....它的工作原理... – VRAwesome