Swift: 仿写Kugou App(一)之框架搭建

2018-04-07  本文已影响0人  yehkong

序言:最近在找工作...在焦急等待面试通知及录取通知的过程中,也找一个项目来练练手,再熟悉熟悉Swift。看了一圈自己手机里的app,遂找了酷狗这个App,会形成一个小系列,记录这次练手过程。

先看下框架简易效果:


kugou.gif

简要说明:

1.png
class BGViewController: UIViewController,MainNavigationDelegate {
    //登录及设置页面
    lazy var accountPage : LoginViewController = {
        return LoginViewController()
    }()
    //主控制器(听说唱控制器)
    lazy var mainController : MainNaviController = {
        let listenController = kugouViewController()
        listenController.mainDelegate = self
        let mainNaviController = MainNaviController.init(rootViewController: listenController)
        return mainNaviController
    }()
}
let titleArr = ["听","看","唱"]
        for i in 0..<3 {
            let btn = UIButton.init(frame: CGRect.init(x: i * 60, y: 0, width: 60, height: 33))
            btn.tag = i
            btn.setTitle(titleArr[i], for: .normal)
            btn.setTitleColor(UIColor.lightGray, for: .normal)
            btn.setTitleColor(UIColor.white, for: .selected)
            
            btn.addTarget(self, action: #selector(changeAction(_:)), for: UIControlEvents.touchUpInside)
            titleBgView?.addSubview(btn)
        }
 override func viewDidLoad() {
        super.viewDidLoad()
        
        let kheight = self.view.bounds.size.height - 60
        mainScrollView = UIScrollView.init()
        mainScrollView?.frame = CGRect.init(x: 0, y: 0, width: self.view.bounds.size.width, height: kheight)
        mainScrollView?.delegate = self
        mainScrollView?.bounces = false
        mainScrollView?.isPagingEnabled = true
        view.addSubview(mainScrollView!)
        // Do any additional setup after loading the view.
        
        listenController.view.frame = CGRect.init(x: 0, y: 0, width: ScreenW, height: kheight)
        mainScrollView?.addSubview(listenController.view)
        
        lookController.view.frame = CGRect.init(x: ScreenW, y: 0, width: ScreenW, height: kheight)
        mainScrollView?.addSubview(lookController.view)
        
        singController.view.frame = CGRect.init(x: 2 * ScreenW, y: 0, width: ScreenW, height: kheight)
        mainScrollView?.addSubview(singController.view)
        
        mainScrollView?.contentSize = CGSize.init(width: 3 * ScreenW, height: kheight)
        
        sharePlayer.view.frame = CGRect.init(x: 0, y: ScreenH - 60, width: ScreenW, height: 60)
        self.addChildViewController(sharePlayer)
        self.view.addSubview(sharePlayer.view)
    }
class PlayerViewController: UIViewController {

    static let SharePlayer = PlayerViewController()
}
后面根据具体的页面及其他业务逻辑继续展开进行扩展
上一篇下一篇

猜你喜欢

热点阅读