UIButtonをアニメーションで動かすとタップイベントを検知できず、困っております。
ググってみたらHittestを使うとうまくいくとの情報が得られたのですが、詳細の実装方法が載っておらず、技術力低めの私では対応が難しい状況です。
現状のコードは下に貼ってあるようなものです。
何か解決方法をご存知の方がいらっしゃいましたら、ご教示いただけますと大変助かります。
ざっくりとした質問になってしまって大変恐縮ですが、何卒よろしくお願いいたします。
Swift
1class ViewController: UIViewController { 2 3 var charaBtn:UIButton! 4 5//中略 6 7func initAnime(){ 8 var nextx = self.charaBtn.frame.origin.x + CGFloat(Int(arc4random() % dist) - Int(dist)/2) 9 var nexty = self.charaBtn.frame.origin.y + CGFloat(Int(arc4random() % dist) - Int(dist)/2) 10 while (nextx < 0 || self.view.frame.size.width - self.charaBtn.frame.width < nextx ) { 11 nextx = self.charaBtn.frame.origin.x + CGFloat(Int(arc4random() % dist) - Int(dist)/2) 12 } 13 while (nexty < 0 || self.view.frame.size.height - self.charaBtn.frame.height < nexty ) { 14 nexty = self.charaBtn.frame.origin.y + CGFloat(Int(arc4random() % dist) - Int(dist)/2) 15 } 16 17 UIView.animateWithDuration(duration, 18 animations: {() -> Void in 19 // アニメーションする処理 20 self.charaBtn.frame.origin.x = nextx 21 self.charaBtn.frame.origin.y = nexty 22 23 }, completion: { finished in 24 self.initAnime() 25 }) 26 } 27}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/13 11:56