Netease-Music-Demo by sss
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

DiscoverViewController.swift 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // DiscoverViewController.swift
  3. // wyy
  4. //
  5. // Created by 施书顺 on 2021/3/5.
  6. //
  7. import UIKit
  8. import SnapKit
  9. class DiscoverViewController: UIViewController {
  10. let searchController = UISearchController()
  11. let leftNavItem = UIBarButtonItem(systemItem: .play)
  12. let rightNavItem = UIBarButtonItem(systemItem: .action)
  13. let newsView = DiscoverNewsView()
  14. let buttonsView = DiscoverButtonsView()
  15. let scrollView = UIScrollView()
  16. let contentView = UIView()
  17. let sideBar = SideBarView()
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. view.backgroundColor = .white
  21. navigationItem.titleView = searchController.searchBar
  22. searchController.hidesNavigationBarDuringPresentation = false
  23. // navigationItem.setLeftBarButton(leftNavItem, animated: false)
  24. navigationItem.setRightBarButton(rightNavItem, animated: false)
  25. // leftNavItem.target = self
  26. // navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(clickedOpenSideBar(sender:)))
  27. view.addSubview(scrollView)
  28. // scrollView.addSubview(contentView)
  29. scrollView.addSubview(newsView)
  30. newsView.snp.makeConstraints{ make in
  31. make.centerX.equalToSuperview()
  32. make.top.equalTo(10)
  33. make.width.equalTo(350)
  34. make.height.equalTo(200)
  35. }
  36. scrollView.addSubview(buttonsView)
  37. buttonsView.snp.makeConstraints{ make in
  38. make.centerX.equalToSuperview()
  39. make.top.equalTo(newsView.snp.bottom).offset(20)
  40. make.width.equalToSuperview()
  41. make.height.equalTo(80)
  42. }
  43. let line1 = UIView()
  44. line1.layer.borderWidth = 1.0
  45. line1.layer.borderColor = UIColor.black.withAlphaComponent(0.1).cgColor
  46. scrollView.addSubview(line1)
  47. line1.snp.makeConstraints{ make in
  48. make.top.equalTo(buttonsView.snp.bottom).offset(5)
  49. make.centerX.equalToSuperview()
  50. make.width.equalToSuperview()
  51. make.height.equalTo(1)
  52. }
  53. let rcmdView = DiscoverRecommendView()
  54. scrollView.addSubview(rcmdView)
  55. rcmdView.snp.makeConstraints{ make in
  56. make.top.equalTo(line1.snp.bottom).offset(10)
  57. make.centerX.equalToSuperview()
  58. make.width.equalToSuperview()
  59. make.height.equalTo(180)
  60. }
  61. let line2 = UIView()
  62. line2.backgroundColor = UIColor.gray.withAlphaComponent(0.1)
  63. scrollView.addSubview(line2)
  64. line2.snp.makeConstraints{ make in
  65. make.top.equalTo(rcmdView.snp.bottom).offset(10)
  66. make.centerX.equalToSuperview()
  67. make.width.equalToSuperview()
  68. make.height.equalTo(10)
  69. }
  70. let popularSongView = DiscoverPopularSongsView()
  71. scrollView.addSubview(popularSongView)
  72. popularSongView.snp.makeConstraints{ make in
  73. make.top.equalTo(line2.snp.bottom).offset(10)
  74. make.centerX.equalToSuperview()
  75. make.width.equalToSuperview()
  76. make.height.equalTo(250)
  77. }
  78. scrollView.frame = view.bounds
  79. scrollView.showsHorizontalScrollIndicator = true
  80. // scrollView.addSubview(sideBar)
  81. // sideBar.snp.makeConstraints{ make in
  82. // make.top.equalTo(0)
  83. // make.left.equalTo(-sideBar.frame.width)
  84. // }
  85. }
  86. override func viewDidLayoutSubviews() {
  87. let contentRect = scrollView.subviews.reduce(into: CGRect.zero, { rect, view in
  88. rect = rect.union(view.frame)
  89. })
  90. scrollView.contentSize = CGSize(width: contentRect.width, height: contentRect.height+60)
  91. }
  92. }