ViewController.swift内で画面をタッチした際の座標を取得し、
取得した座標によって特定の値を返すクラスをpoint_control.swift内に記述しました。
しかし、実行してみると画面をタッチした段階で強制的にSimulatorが終了してしまいました。
ViewControllerでの呼び出し方が悪いのでしょうか教えてください。
ViewController.swift
class ViewController: UIViewController { /*CGPoint:対象オブジェクトの位置を管理するクラスです。*/ var tapLocation: CGPoint = CGPoint() private var myButton: UIButton! @IBOutlet var location: UILabel! @IBOutlet var bord_point: UILabel! var point = "nil" //インスタンス作成 var pointControl = point_control() override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { // タッチイベントを取得する let touch = touches.first // タップした座標を取得する tapLocation = touch!.locationInView(self.view) /*labelに変数を入れる*/ location.text = String(tapLocation) point = String(pointControl.point_translate(Double(tapLocation.x),point_y:Double(tapLocation.y))) bord_point.text = point } ...続く
point_control.swift
import
1class point_control { 2 var test_number:Int 3 4 init(){ 5 test_number = 0 6 } 7 8 func point_translate(point_x:Double,point_y:Double) -> Int{ 9 10 11 if point_y >= 0 && point_y <= 250 || point_y >= 730 {//上段または下段であった場合 12 13 if point_y >= 183.5 && point_y <= 207.5{//上段のマイナス列 14 if point_x >= 63.5 && point_x <= 88{ 15 test_number = 1 16 }else if point_x >= 98.5 && point_x <= 122{ 17 test_number = 2 18 }else if point_x >= 131.5 && point_x <= 157.5{ 19 test_number = 3 20 21...続く
回答2件
あなたの回答
tips
プレビュー