第二周第二天上下翻动图片

视图控制器

  • 上下翻
  • 添加第二个界面SecondController和第三个界面ThreeController
  • 在ViewController里面写
 self.view.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1)
        //视图控制器
        //UIControl子类
        //手势
        let btn = UIButton(type:.system)
        btn.frame = CGRect(x: 100, y: 100, width: 50, height: 40)
        btn.addTarget(self,action: #selector(btnAction(btn:)), for: .touchUpInside)
        btn.setTitle("登陆完成", for: .normal)
        
        self.view.addSubview(btn)
        
    }
    func btnAction(btn:UIButton){
        //摸态推动下一个界面,一般用于注册
        let vc = SecondViewController()
        //1要推出的下一个控制器
        //2是否有动画
        //3推出完成之后回掉
        self.present(vc,animated: true){
            
        }
       }
    //视图将要显示在屏幕上
    override func  viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    //显示在屏幕上
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    }
    //视图将要从屏幕上消失
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    //已经消失在屏幕上
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
    }
    //控制器被销毁
    deinit{
        
    }


  • SecondController里面写
self.view.backgroundColor = #colorLiteral(red: 0.9686274529, green: 0.78039217, blue: 0.3450980484, alpha: 1)

       let btn = UIButton(type:.system)
       btn.frame = CGRect(x: 100, y: 100, width: 50, height: 40)
       btn.addTarget(self,action: #selector(btnAction(btn:)), for: .touchUpInside)
       btn.setTitle("登陆完成", for: .normal)
       
       self.view.addSubview(btn)
       
   }
   func btnAction(btn:UIButton){
      
        //当前页面回收回去
       self.dismiss(animated: true, completion: nil)
       
   }
   
   

  • 在threeScontroller里面写

-在ThreeScontrollor里面写
// 属性传值
   var secondeVC : SecondViewController!
   
   override func viewDidLoad() {
       super.viewDidLoad()
       self.view.backgroundColor = UIColor.green
       let btn = UIButton(type: .system)
       btn.frame = CGRect(x: 100, y: 100, width: 50, height: 40)
       btn.addTarget(self , action: #selector(btnAction(btn:)), for: .touchUpInside)
       btn.setTitle("登陆完成", for: .normal)
       self.view.addSubview(btn)
   }
   
   func btnAction(btn: UIButton) {
       self.secondeVC.dismiss(animated: true, completion: nil)
   }


你可能感兴趣的:(第二周第二天上下翻动图片)