IOS] 팝업 창 만들기

아주 간단한 기본 팝업 창!

작은 팝업창이 그 위에 따로 뜨는게 아니라

그냥 아예 팝업화면페이지를 만들어서 휘리릭 화면 전환을 하는 간단한 눈속임(?)방식입니다!

 

 

 

첫번째 viewcontroller:  누르면 팝업이 튀어나올 버튼 하나 만들어 줍니다. 

버튼 작동 함수만 작성해주면 됩니다.

 @IBAction func POPUPView(_ sender: Any) {
        //내비게이션을 이용한 화면 전환
        let storyboard = UIStoryboard.init(name: "POPUP", bundle: nil)
        let alertPopupVC = storyboard.instantiateViewController(withIdentifier: "PopupVC") as! POPUP
        
        alertPopupVC.modalPresentationStyle = .overCurrentContext
        alertPopupVC.modalTransitionStyle = .crossDissolve
        
        self.present(alertPopupVC, animated: true, completion: nil)
        
    }

 

import UIKit



class ViewController: UIViewController {

    
    @IBOutlet weak var POPButton: UIButton!

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    

 
    @IBAction func POPUPView(_ sender: Any) {
        
        let storyboard = UIStoryboard.init(name: "POPUP", bundle: nil)
        let alertPopupVC = storyboard.instantiateViewController(withIdentifier: "PopupVC") as! POPUP
        
        alertPopupVC.modalPresentationStyle = .overCurrentContext
        alertPopupVC.modalTransitionStyle = .crossDissolve
        
        self.present(alertPopupVC, animated: true, completion: nil)
        
    }
    
    
}

 

 

 

두번째 viewcontroller는 (눈속임)팝업 화면을 만들거에요.

얘도 버튼만 해주면 됩니다! 

@IBAction func ClosePopup(_ sender: Any) {
	//돌아가는 버튼
        self.dismiss(animated: true, completion: nil)

    }

 

import UIKit


class POPUP: UIViewController {

    @IBOutlet weak var BackButton: UIButton!
    @IBOutlet weak var PopupLabel: UILabel!
    

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    
     
    
    @IBAction func ClosePopup(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)

    }
    
}

 

 

 

아직 많이 부족해서 이런 눈속임 팝업만 사용합니다...ㅎㅎ