###前提・実現したいこと
swiftでモーダルを表示させるのですが、
そのモーダルを閉じるボタンがクリックしても、閉じることができません。そのモーダルを閉じることが目標です。
###発生している問題・エラーメッセージ
エラーメッセージは表示されません。モーダルは表示されます。
以下closeModalのprintlnは出力されません。
###ソースコード
swift
1import UIKit 2 3 4class ModalViewController : UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 9 self.view.backgroundColor = UIColor.rgb(r: 0, g: 0, b: 0, alpha: 0.5) 10 11 let modal_view = UILabel(frame: CGRectMake(0, 0, 300, 300)) 12 modal_view.backgroundColor = UIColor.whiteColor() 13 modal_view.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height / 2) 14 self.view.addSubview(modal_view) 15 16 let close_button = UIButton(frame: CGRectMake(0, 0, 250, 50)) 17 close_button.layer.borderColor = UIColor.grayColor().CGColor 18 close_button.layer.borderWidth = 3 19 close_button.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height / 2 + 100) 20 close_button.setTitle("もどる", forState: .Normal) 21 close_button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal) 22 close_button.tag = 5 23 close_button.addTarget(self, action: "closeModal:", forControlEvents: .TouchUpInside) 24 self.view.addSubview(close_button) 25 } 26 27 /* 28 Buttonを押した時に呼ばれるメソッド. 29 */ 30 func closeModal(sender: AnyObject) { 31 println("きてる") 32 self.dismissViewControllerAnimated(true, completion: nil) 33 } 34}
swift
1 // 動画が終了したときに呼ばれる関数 2 func playerItemEnd(notification: NSNotification){ 3 videoPlayer.pause() 4 println("全ての動画が終了") 5 // secondViewControllerのインスタンス生成. 6 let Modal = ModalViewController() 7 8 // モーダルをフェードインさせる 9 Modal.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve 10 // bootstrapのモーダルっぽくする 11 Modal.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext 12 13 self.presentViewController(Modal, animated: true, completion: nil) 14 } 15
###補足情報(言語/FW/ツール等のバージョンなど)
xcode6.4
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/11/10 10:15