お忙しいなかしょうもない質問を見てくださってありがとうございます。
- 要望:背景がまっくろにならないでほしい
Show ボタンを押すと self.present で UIViewController を重ねます。
newViewCOntrollerが表示された状態です。背景が透過のためこの状態だと最初のViewControllerが表示されています。
tabのsecondをタップしてSecondViewControllerに遷移します。
tabのfirstをタップしてFirstViewControllerに遷移します。
そうすると、newVIewControllerは表示されていますが、その後ろのViewControllerが表示されていません。
Hideボタンをタップするとdismissが呼ばれてnewViewControllerが見えなくなり、完全に真っ暗になります。
newViewControllerを見えなくした後に、SecondViewControllerに遷移します。
newViewControllerを非表示にした後に戻ってくるとちゃんと表示されます。
- 要望としては、newViewCOntrollerを表示した状態でtabでの遷移を行なっても、背景真っ黒にならずにちゃんと表示してほしいです。
下記コードです
Swift
1import UIKit 2 3class FirstViewController: UIViewController { 4 5 lazy private var newViewController: UIViewController = { 6 let v = UINib(nibName: "NewViewController", bundle: nil).instantiate(withOwner: self, options: nil)[0] as! UIViewController 7 v.modalTransitionStyle = .crossDissolve 8 v.modalPresentationStyle = .overCurrentContext 9 10 return v 11 }() 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 // Do any additional setup after loading the view, typically from a nib. 16 } 17 18 override func didReceiveMemoryWarning() { 19 super.didReceiveMemoryWarning() 20 // Dispose of any resources that can be recreated. 21 } 22 23 @IBAction func didTapShowButton(_ sender: UIButton) { 24 self.present(self.newViewController, animated: true, completion: nil) 25 } 26 27 28 @IBAction func didTapHideButton(_ sender: UIButton) { 29 self.dismiss(animated: true, completion: nil) 30 } 31} 32
Swift
1import UIKit 2 3class SecondViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 } 9 10 override func didReceiveMemoryWarning() { 11 super.didReceiveMemoryWarning() 12 // Dispose of any resources that can be recreated. 13 } 14 15 16} 17
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/15 02:05
2017/02/15 04:55
2017/02/15 05:43