#selector(ViewController.drawGesture(_:)))
の箇所で
Type 'ViewController' has no member 'drawGesture' エラーになります。
下記にfuncはあるのですがどこが悪いか教えて戴けませんか。
func drawGesture(sender: AnyObject) {
構文の概要
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate { //UIScrollViewDelegateを追加
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var canvasView: UIImageView!
@IBOutlet weak var sliderValue: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
private func prepareDrawing() {
//実際のお絵描きで言う描く手段(色えんぴつ?クレヨン?絵の具?など)の準備
let myDraw = UIPanGestureRecognizer(target: self, action: #selector(ViewController.drawGesture(_:)))
//let myDraw = UIPanGestureRecognizer(target: self, action: #selector(ViewController.drawGesture(sender:))
myDraw.maximumNumberOfTouches = 1
self.scrollView.addGestureRecognizer(myDraw)
}
func drawGesture(sender: AnyObject) {
guard let drawGesture = sender as? UIPanGestureRecognizer else {
print("drawGesture Error happened.")
return
}
guard let canvas = self.canvasView.image else {
fatalError("self.pictureView.image not found")
}
let touchPoint = drawGesture.location(in: canvasView) //タッチ座標を取得
switch drawGesture.state {
case .began:
lastPoint = touchPoint //タッチ座標をlastTouchPointとして保存する
//touchPointの座標はscrollView基準なのでキャンバスの大きさに合わせた座標に変換しなければいけない
//LastPointをキャンバスサイズ基準にConvert
let lastPointForCanvasSize = convertPointForCanvasSize(originalPoint: lastPoint!, canvasSize: canvas.size)
bezierPath = UIBezierPath()
guard let bzrPth = bezierPath else {
fatalError("bezierPath Error")
}
bzrPth.lineCapStyle = .round //描画線の設定 端を丸くする
//bzrPth.lineWidth = defaultLineWidth //描画線の太さ
bzrPth.lineWidth = lineWidth! //描画線の太さ
bzrPth.move(to: lastPointForCanvasSize)
case .changed:
※ 修正
//この箇所はそのままで
① let myDraw = UIPanGestureRecognizer(target: self, action: #selector(ViewController.drawGesture(_:)))
② @objc func drawGesture(sender: Any) --- この箇所を変えましたが
①のところで Type 'ViewController' has no member 'drawGesture'がやはり表示されます。