add correct code
[app.GameProjectTest] / GameProjectTest / HomeController.swift
diff --git a/GameProjectTest/HomeController.swift b/GameProjectTest/HomeController.swift
new file mode 100644 (file)
index 0000000..35c2486
--- /dev/null
@@ -0,0 +1,155 @@
+//
+//  HomeViewController.swift
+//  UPlab_MVC
+//
+//  Created by Ernest.lee on 17/10/2019.
+//  Copyright © 2019 Ernest.lee. All rights reserved.
+//
+
+import UIKit
+import SceneKit
+       
+public extension UIView {
+    enum ViewSide {
+        case Left, Right, Top, Bottom
+    }
+    func addBorder(toSide side: ViewSide, withColor color: CGColor, andThickness thickness: CGFloat) {
+
+        let border = CALayer()
+        border.backgroundColor = color
+
+        switch side {
+        case .Left: border.frame = CGRect(x: frame.minX, y: frame.minY, width: thickness, height: frame.height); break
+        case .Right: border.frame = CGRect(x: frame.maxX, y: frame.minY, width: thickness, height: frame.height); break
+        case .Top: border.frame = CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: thickness); break
+        case .Bottom: border.frame = CGRect(x: frame.minX, y: frame.maxY, width: frame.width, height: thickness); break
+        }
+
+        layer.addSublayer(border)
+    }
+    func anchor(top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?,
+                paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat,
+                width: CGFloat, height: CGFloat, enableInsets: Bool) {
+        var topInset = CGFloat(0)
+        var bottomInset = CGFloat(0)
+        
+        if #available(iOS 11, *), enableInsets {
+            let insets = self.safeAreaInsets
+            topInset = insets.top
+            bottomInset = insets.bottom
+            
+        }
+        
+        
+        translatesAutoresizingMaskIntoConstraints = false
+        
+        if let top = top {
+            self.topAnchor.constraint(equalTo: top, constant: paddingTop+topInset).isActive = true
+        }
+        if let left = left {
+            self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true
+        }
+        if let right = right {
+            rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = true
+        }
+        if let bottom = bottom {
+            bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom-bottomInset).isActive = true
+        }
+        if height != 0 {
+            heightAnchor.constraint(equalToConstant: height).isActive = true
+        }
+        if width != 0 {
+            widthAnchor.constraint(equalToConstant: width).isActive = true
+        }
+        
+    }
+}
+/*
+ HomeVC is the main controller, it is responsible for Nav bar control and setting up childVC
+ */
+
+class HomeController: UIViewController{
+    
+   
+  
+    //MARK: Properties
+    let mapVC: GameViewController = GameViewController()
+    
+    
+     
+    //MARK: Init
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        view.backgroundColor = .gray
+        setUpVC()
+        setUpNavBar()
+        setConstraints()
+    }
+    
+    
+    
+    func setUpVC(){
+       
+        //Map VC
+        
+        addChild(mapVC)
+
+      //  if let frame = nil {
+      //      mapVC.view.frame = frame
+      //  }
+
+        view.addSubview(mapVC.view)
+        mapVC.didMove(toParent: self)
+      
+        
+    }
+    
+    
+    func setConstraints(){
+        /*
+        mapVC.view.anchor(top: nil, left: nil,
+                          bottom: nil, right: nil,
+                          paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0, enableInsets: false)
+        if #available(iOS 11.0, *) {
+            mapVC.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
+        }
+        
+        mapVC.view.addBorder(toSide: .Left, withColor: UIColor.black.cgColor, andThickness: 1.0)
+        */
+       
+        
+    }
+}
+
+
+
+extension HomeController {
+    func setUpNavBar(){
+        navigationController?.navigationBar.barTintColor = .white
+        navigationController?.navigationBar.isTranslucent = true
+        navigationController?.navigationBar.backgroundColor = .white
+        
+       
+        let threeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "Image").withRenderingMode(.alwaysOriginal),
+                                          style: .plain,
+                                          target: self,
+                                          action: #selector(handleThree))
+        
+
+        
+        
+        navigationItem.leftBarButtonItems = [threeButton]
+         
+    }
+    
+    //MARK: - Nav Bar Handler
+    
+    
+    @objc func handleThree(){
+        //delegate?.handleThreeToggle()
+        
+    }
+   
+}