Last active
August 29, 2015 14:13
-
-
Save matsuhisa/7c4bc6a22e3a20fb3635 to your computer and use it in GitHub Desktop.
モーダルウィンドウをStoryboardで設定して、Delegateで値の受け渡しをする ref: http://qiita.com/matsuhisa@github/items/809c36fb766fb1049d4a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// storyboard で設定したViewを呼び出します | |
// - idで「second」を指定しています | |
// - SecondViewController というclassを別で作っています | |
var secondView:SecondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("second") as SecondViewController | |
// 透過などが有効になるように設定 | |
secondView.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen | |
// モーダルウィンドウを呼び出します | |
self.presentViewController(secondView as UIViewController, animated: true, completion:nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
secondView.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SecondView.swift | |
// TestAppInputForm02 | |
import UIKit | |
class SecondViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Dark)) | |
visualEffectView.frame = self.view.bounds | |
self.view.backgroundColor = UIColor.clearColor() | |
self.view.addSubview(visualEffectView) | |
self.view.sendSubviewToBack(visualEffectView) | |
// 以下略 | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class SecondViewController: UIViewController { | |
@IBOutlet weak var BackButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// 戻る(閉じる)ボタン | |
BackButton.addTarget(self, action: "backToMain:", forControlEvents: .TouchUpInside) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func backToMain(sender: AnyObject?) { | |
self.dismissViewControllerAnimated(true, completion: nil); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThirdViewController: UIViewController { | |
@IBOutlet weak var AllCloseButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// ボタンの設定 | |
AllCloseButton.addTarget(self, action: "allClose:", forControlEvents: .TouchUpInside) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func allClose(sender: AnyObject?) { | |
UIApplication.sharedApplication().keyWindow.rootViewController?.dismissViewControllerAnimated(true, completion: nil) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@objc protocol ModalViewDelegate { | |
func saveText(textdata:String) | |
} | |
class ThirdViewController: UIViewController { | |
var delegate:ModalViewDelegate! = nil | |
@IBOutlet weak var InputTextThird: UIPlaceHolderTextView! | |
@IBOutlet weak var SaveButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// ボタンの設定 | |
SaveButton.addTarget(self, action: "saveSubmit:", forControlEvents: .TouchUpInside) | |
// rootViewからdelegate を設定する | |
var rootView = UIApplication.sharedApplication().keyWindow.rootViewController as ViewController | |
self.delegate = rootView | |
} | |
func allClose(sender: AnyObject?) { | |
UIApplication.sharedApplication().keyWindow.rootViewController?.dismissViewControllerAnimated(true, completion: nil) | |
} | |
func saveSubmit(sender: AnyObject?) { | |
var inputText:String = InputTextThird.text | |
self.delegate.saveText(inputText) | |
// 閉じる | |
self.allClose(sender) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, ModalViewDelegate{ | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
func saveText(textdata:String){ | |
ImutView.text = textdata | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class SecondViewController: UIViewController { | |
@IBOutlet weak var BackButton: UIButton! | |
@IBOutlet weak var ToThirdViewBbutton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Dark)) | |
visualEffectView.frame = self.view.bounds | |
self.view.backgroundColor = UIColor.clearColor() | |
self.view.addSubview(visualEffectView) | |
self.view.sendSubviewToBack(visualEffectView) | |
BackButton.addTarget(self, action: "backToMain:", forControlEvents: .TouchUpInside) | |
ToThirdViewBbutton.addTarget(self, action: "toThird:", forControlEvents: .TouchUpInside) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func backToMain(sender: AnyObject?) { | |
self.dismissViewControllerAnimated(true, completion: nil); | |
} | |
func toThird(sender: AnyObject?) { | |
var thirdView:AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("third") | |
self.presentViewController(thirdView as UIViewController, animated: true, completion:nil) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@objc protocol ModalViewDelegate { | |
func saveText(textdata:String) | |
} | |
class ThirdViewController: UIViewController { | |
var delegate:ModalViewDelegate! = nil | |
@IBOutlet weak var ThisCloseButton: UIButton! | |
@IBOutlet weak var AllCloseButton: UIButton! | |
@IBOutlet weak var InputTextThird: UIPlaceHolderTextView! | |
@IBOutlet weak var SaveButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// TextViewの設定 | |
InputTextThird.placeHolder = "3枚目のViewです。ここに本文を書き、1枚目に送ります" | |
// ボタンの設定 | |
ThisCloseButton.addTarget(self, action: "backToMain:", forControlEvents: .TouchUpInside) | |
AllCloseButton.addTarget(self, action: "allClose:", forControlEvents: .TouchUpInside) | |
SaveButton.addTarget(self, action: "saveSubmit:", forControlEvents: .TouchUpInside) | |
// rootViewからdelegate を設定する | |
var rootView = UIApplication.sharedApplication().keyWindow.rootViewController as ViewController | |
self.delegate = rootView | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func backToMain(sender: AnyObject?) { | |
self.dismissViewControllerAnimated(true, completion: nil); | |
} | |
func allClose(sender: AnyObject?) { | |
UIApplication.sharedApplication().keyWindow.rootViewController?.dismissViewControllerAnimated(true, completion: nil) | |
} | |
func saveSubmit(sender: AnyObject?) { | |
var inputText:String = InputTextThird.text | |
self.delegate.saveText(inputText) | |
// 閉じる | |
self.allClose(sender) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, ModalViewDelegate{ | |
@IBOutlet weak var TestWebView: UIWebView! | |
@IBOutlet weak var ImutView: UIPlaceHolderTextView! | |
@IBOutlet weak var SaveButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// TextViewの設定 | |
ImutView.placeHolder = "本文です。" | |
ImutView.placeHolderColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.5) | |
// ボタンの設定 | |
SaveButton.addTarget(self, action: "click:", forControlEvents: .TouchUpInside) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func click(sender: AnyObject?) { | |
var secondView:SecondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("second") as SecondViewController | |
secondView.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen | |
self.presentViewController(secondView as UIViewController, animated: true, completion:nil) | |
} | |
func saveText(textdata:String){ | |
ImutView.text = textdata | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment