下記のようにコードで、UIButtonを生成し、25個配置し、
それぞれにタッチイベントを設置しているのですが、
そのタッチイベントが画面遷移後でも、効いてしまい。
タッチイベントがあった場所をクリックすると反応してしまいアプリがおかしくなってしまいます。
また、UIApplication.sharedApplication().beginIgnoringInteractionEvents()
を使って、タッチイベントを無効に画面遷移してしまうと今度は遷移先の画面で、
タッチイベントが無効になってしまい苦戦しております。
よくありそうなケースなのですが、
前のページのタッチイベントだけ削除みたいな方法をご存知の方教えてください。
まだ、swift歴3日程度ですが、ご存知の方いましたら
教えていただけますと幸いです。
lang
1 2 override func viewDidLoad() { 3 super.viewDidLoad() 4 5 let appFrameSize = UIScreen.mainScreen().applicationFrame.size 6 // ボタンのサイズ 7 var levelIconSize:Int = Int(appFrameSize.width) / 5 8 9 10 11 for i in 0...24 { 12 13 let x = levelIconSize * (i % 5) + (levelIconSize / 2) 14 let y = levelIconSize * (i / 5) + (Int(appFrameSize.height) / 3) 15 16 let image = UIImage(named: "btn_image") as UIImage? 17 let imageButton = UIButton() 18 imageButton.tag = i 19 imageButton.frame = CGRectMake(0, 0, CGFloat(levelIconSize), CGFloat(levelIconSize)) 20 imageButton.layer.position = CGPoint(x:CGFloat(x), y:CGFloat(y)) 21 imageButton.setBackgroundImage(image, forState:nil) 22 23 //ボタンイベント設定 24 imageButton.addTarget(self, action: "tapBtn:", forControlEvents: .TouchUpInside) 25 //ボタンを追加 26 self.view.addSubview(imageButton) 27 } 28} 29 30〜〜 31 32func tapBtn(sender: UIButton) { 33 // segueを使って、次の画面に遷移 34 performSegueWithIdentifier("toSceneSegue", sender: sender) 35 36} 37 38// 次の画面に引数を渡すため 39override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 40 41 if segue.identifier == "toSceneSegue" { 42 43 println("nextpage tag (sender.tag)") 44 let nextVC: testViewController = segue.destinationViewController as testViewController 45 nextVC.modalTransitionStyle = UIModalTransitionStyle.PartialCurl 46 nextVC.selectLv = sender.tag 47 } 48} 49
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/02/04 04:12
2015/02/04 04:14
2015/02/04 04:42