Swift: 仿写Kugou App(一)之框架搭建
2018-04-07 本文已影响0人
yehkong
序言:最近在找工作...在焦急等待面试通知及录取通知的过程中,也找一个项目来练练手,再熟悉熟悉Swift。看了一圈自己手机里的app,遂找了酷狗这个App,会形成一个小系列,记录这次练手过程。
- 本次项目地址:仿写Kugou
- 小系列其他文章:
暂定:Swift: 仿写Kugou App(二)之Charles抓取数据
先看下框架简易效果:
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
}()
}
- 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)
}
- 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)
}
- PlayerViewController定义了播放器单例
class PlayerViewController: UIViewController {
static let SharePlayer = PlayerViewController()
}