overrideに関しまして、質問をさせて頂きます。
質問内容は、下記のとおりです。
■質問
ボタンをタップした後に、
touchesBeganメソッドとtouchesMovedメソッドをオーバーライドするには
どのようなコーディングをすべきでしょうか。
・環境
xcode8/swift3
現在、以下のようなコーディングで
touchesBeganメソッドとtouchesMovedメソッドをオーバーライドしています。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { drawView = DrawView() drawView.frame = canvasView.frame drawView.backgroundColor = UIColor.clear drawView.color = colorArray[colorNum] canvasView.addSubview(drawView) let touch = touches.first! let point = touch.location(in: self.view) drawView.points.append(point) } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = touches.first! let point = touch.location(in: self.view) drawView.points.append(point) drawView.setNeedsDisplay() } }
しかしアプリの仕様上、ボタンをタップした後に、
touchesBeganメソッドとtouchesMovedメソッドをオーバーライドさせたいため
以下のようなコーディングをしました。
@IBAction func closeButton(_ sender: UIButton) { mainScrollView.isHidden = true buttonClose.isHidden = true override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { drawView = DrawView() drawView.frame = canvasView.frame drawView.backgroundColor = UIColor.clear drawView.color = colorArray[colorNum] canvasView.addSubview(drawView) let touch = touches.first! let point = touch.location(in: self.view) drawView.points.append(point) } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = touches.first! let point = touch.location(in: self.view) drawView.points.append(point) drawView.setNeedsDisplay() } }
このコードでは、xcodeがoverrideを消しなさいというメッセージが表示されます。
しかしoverrideを消しても
touchesBeganメソッドとtouchesMovedメソッドはオーバーライドされません。
(私の文法自体間違っているかもしれないのですが)
ボタンをタップした後に、
touchesBeganメソッドとtouchesMovedメソッドをオーバーライドするには
どのようなコーディングをすべきでしょうか。
ご教示頂けますでしょうか、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/18 06:51 編集
2017/01/18 05:32
2017/01/18 06:50
2017/01/18 06:58 編集