美文网首页
Swift: 仿写Kugou App(一)之框架搭建

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

作者: yehkong | 来源:发表于2018-04-07 20:50 被阅读0次

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

    先看下框架简易效果:


    kugou.gif

    简要说明:

    • 1 .项目文件基本机构,类文件如下:
    1.png
    • 2 .容器控制器内装的控制器,在点击leftItem后进行侧滑展示容器内的控制器:
    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
        }()
    }
    
      1. BaceViewController内定义听、看、唱切换按钮等
    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)
            }
    
      1. kugouViewController定义Scrollview添加听看唱及播放器控制器作为子控制和子视图
     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)
        }
    
      1. PlayerViewController定义了播放器单例
    class PlayerViewController: UIViewController {
    
        static let SharePlayer = PlayerViewController()
    }
    
    后面根据具体的页面及其他业务逻辑继续展开进行扩展

    相关文章

      网友评论

          本文标题:Swift: 仿写Kugou App(一)之框架搭建

          本文链接:https://www.haomeiwen.com/subject/syvyhftx.html