UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법
환경
・Swift3
・Xcode8
그래, 그래! ! ! ! ! ! 위베포포w

위와 같이 UIView 위에 UIButton을 넣어 보면 PresentsViewController를 호출하지 않고 화면 전환을 할 수 없습니다. 어려움, 최악입니다.
infoClick() 함수 정의
UIButton의 Action에서 infoClick()
함수를 호출해보십시오. 화면 전환이 가능합니다!
func infoClick() {
let storyboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
let vc: CampainDetailView = storyboard.instantiateViewControllerWithIdentifier("campainDetailView") as! CampainDetailView
let currentController = self.getCurrentViewController()
currentController?.presentViewController(vc, animated: false, completion: nil)
}
이 함수는 루트 뷰 컨트롤러를 창조합니다!
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
좌우로 전환
앱처럼 좌우로 천이시키고 싶다면 아래와 같이 쓰면 좋다고 생각합니다. 모든 소스를 올려 둡니다.
@IBAction func SettingButton(_ sender: Any) {
let storyboard: UIStoryboard = UIStoryboard (name: "Time", bundle: nil)
let vc: TimeViewController = storyboard.instantiateViewController(withIdentifier: "Time") as! TimeViewController
let currentController = self.getCurrentViewController()
//右に遷移する
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
//kCATransitionFromLeftにすれば左に遷移します
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
currentController?.present(vc, animated: false, completion: nil)
}
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.shared.keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
참고
How can I call presentViewController in UIView class?
Swift3 – PresentsViewController에서 좌우로 화면 전환하는 방법
UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법
Reference
이 문제에 관하여(UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/rh_/items/73f2e26922449948a50b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)

위와 같이 UIView 위에 UIButton을 넣어 보면 PresentsViewController를 호출하지 않고 화면 전환을 할 수 없습니다. 어려움, 최악입니다.
infoClick() 함수 정의
UIButton의 Action에서 infoClick()
함수를 호출해보십시오. 화면 전환이 가능합니다!
func infoClick() {
let storyboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
let vc: CampainDetailView = storyboard.instantiateViewControllerWithIdentifier("campainDetailView") as! CampainDetailView
let currentController = self.getCurrentViewController()
currentController?.presentViewController(vc, animated: false, completion: nil)
}
이 함수는 루트 뷰 컨트롤러를 창조합니다!
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
좌우로 전환
앱처럼 좌우로 천이시키고 싶다면 아래와 같이 쓰면 좋다고 생각합니다. 모든 소스를 올려 둡니다.
@IBAction func SettingButton(_ sender: Any) {
let storyboard: UIStoryboard = UIStoryboard (name: "Time", bundle: nil)
let vc: TimeViewController = storyboard.instantiateViewController(withIdentifier: "Time") as! TimeViewController
let currentController = self.getCurrentViewController()
//右に遷移する
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
//kCATransitionFromLeftにすれば左に遷移します
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
currentController?.present(vc, animated: false, completion: nil)
}
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.shared.keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
참고
How can I call presentViewController in UIView class?
Swift3 – PresentsViewController에서 좌우로 화면 전환하는 방법
UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법
Reference
이 문제에 관하여(UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/rh_/items/73f2e26922449948a50b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
func infoClick() {
let storyboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
let vc: CampainDetailView = storyboard.instantiateViewControllerWithIdentifier("campainDetailView") as! CampainDetailView
let currentController = self.getCurrentViewController()
currentController?.presentViewController(vc, animated: false, completion: nil)
}
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
좌우로 전환
앱처럼 좌우로 천이시키고 싶다면 아래와 같이 쓰면 좋다고 생각합니다. 모든 소스를 올려 둡니다.
@IBAction func SettingButton(_ sender: Any) {
let storyboard: UIStoryboard = UIStoryboard (name: "Time", bundle: nil)
let vc: TimeViewController = storyboard.instantiateViewController(withIdentifier: "Time") as! TimeViewController
let currentController = self.getCurrentViewController()
//右に遷移する
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
//kCATransitionFromLeftにすれば左に遷移します
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
currentController?.present(vc, animated: false, completion: nil)
}
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.shared.keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
참고
How can I call presentViewController in UIView class?
Swift3 – PresentsViewController에서 좌우로 화면 전환하는 방법
UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법
Reference
이 문제에 관하여(UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/rh_/items/73f2e26922449948a50b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
@IBAction func SettingButton(_ sender: Any) {
let storyboard: UIStoryboard = UIStoryboard (name: "Time", bundle: nil)
let vc: TimeViewController = storyboard.instantiateViewController(withIdentifier: "Time") as! TimeViewController
let currentController = self.getCurrentViewController()
//右に遷移する
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
//kCATransitionFromLeftにすれば左に遷移します
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
currentController?.present(vc, animated: false, completion: nil)
}
func getCurrentViewController() -> UIViewController? {
if let rootController = UIApplication.shared.keyWindow?.rootViewController {
var currentController: UIViewController! = rootController
while( currentController.presentedViewController != nil ) {
currentController = currentController.presentedViewController
}
return currentController
}
return nil
}
How can I call presentViewController in UIView class?
Swift3 – PresentsViewController에서 좌우로 화면 전환하는 방법
UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법
Reference
이 문제에 관하여(UIView 위에 놓은 UIButton에서 PresentsViewController를 호출하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/rh_/items/73f2e26922449948a50b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)