我試圖將我的代碼從obj-c移植到swift,但遇到了很多麻煩。如何覆蓋swift中的UIView.pointInside?
的問題之一是覆蓋一個UIView類的pointInside:如果我添加
/xxx.swift:37:10: Method 'pointInside(_:withEvent:)' with Objective-C selector 'pointInside:withEvent:' conflicts with method 'pointInside(_:withEvent:)' from superclass 'UIView' with the same Objective-C selector
「:
class MyView : UIView{
func pointInside(point: CGPoint, withEvent event: UIEvent) -> Bool {
if point.x < 0 {
return false
} else {
return true
}
}}
如果我不加「覆蓋」,我會得到這個錯誤覆蓋「,我會得到這個錯誤:
/xxx.swift:37:19: Method does not override any method from its superclass
根據文檔,應該有一個pointInside函數