|
@@ -7,24 +7,231 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
+import JXSegmentedView
|
|
|
+import RxSwift
|
|
|
|
|
|
class OtherPersonalCenterViewController: BaseViewController {
|
|
|
|
|
|
+ let JXTableHeaderViewHeight: Int = Int(140 + kNavBarTotalHeight)
|
|
|
+ let JXheightForHeaderInSection: Int = 44
|
|
|
+ var cmsTemplateTitles = ["发布 0", "收藏 0", "分享 0"]
|
|
|
+ var otherPersonalCenterVCType : Int = 0
|
|
|
+
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
-
|
|
|
- // Do any additional setup after loading the view.
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+ setupData()
|
|
|
}
|
|
|
|
|
|
+ override func setupViews() {
|
|
|
+ otherHeaderContainerView.addSubview(otherHeaderView)
|
|
|
+ view.addSubview(segmentedView)
|
|
|
+ view.addSubview(pagingView)
|
|
|
+ view.insertSubview(navigationBar, aboveSubview: pagingView)
|
|
|
+ setnavigationBar()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 设置navigationBar
|
|
|
+ func setnavigationBar() {
|
|
|
+ navigationBar.addSubview(navigationBgView)
|
|
|
+ navigationBar.addSubview(avatarButton)
|
|
|
+ navigationBar.addSubview(nameButton)
|
|
|
+ navigationBar.insertSubview(navigationBgView, aboveSubview: navigationBar.backgroundImageView)
|
|
|
+ navigationBar.backgroundImageView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth)
|
|
|
+ navigationBar.backgroundImageView.contentMode = .scaleAspectFill
|
|
|
+ navigationBar.clipsToBounds = true
|
|
|
+ navigationBar.wr_setRightButton(image: kImage(name: "center_share")!)
|
|
|
+ // 设置导航栏显示图片
|
|
|
+ navigationBar.barBackgroundImage = UIImage(named: "Rectangle 2")
|
|
|
+ // 设置初始导航栏透明度
|
|
|
+ navigationBar.wr_setBackgroundAlpha(alpha: 0)
|
|
|
+ // 设置状态栏style
|
|
|
+ statusBarStyle = .lightContent
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ navigationBgView.snp.makeConstraints { (make) in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+ avatarButton.snp.makeConstraints { (make) in
|
|
|
+// make.left.equalTo(navigationBar.snp_right).offset(8)
|
|
|
+ make.left.equalTo(8)
|
|
|
+ make.size.equalTo(20)
|
|
|
+ make.centerY.equalTo(navigationBar.rightButton)
|
|
|
+ }
|
|
|
+ nameButton.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(avatarButton)
|
|
|
+ make.left.equalTo(avatarButton.snp_right).offset(4)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override func setupData() {
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 刷新页面
|
|
|
+ func reloadData() {
|
|
|
+ segmentedDataSource.titles = cmsTemplateTitles
|
|
|
+ segmentedView.indicators = [indicator]
|
|
|
+ self.segmentedDataSource.reloadData(selectedIndex: otherPersonalCenterVCType)
|
|
|
+ self.segmentedView.defaultSelectedIndex = otherPersonalCenterVCType
|
|
|
+ self.segmentedView.reloadData()
|
|
|
+ self.pagingView.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var avatarButton: UIButton = {
|
|
|
+ let avatarButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ avatarButton.setImage(kImage(name: "defaul_tavatar"), for: UIControl.State.normal)
|
|
|
+ avatarButton.alpha = 0
|
|
|
+ return avatarButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var nameButton: UIButton = {
|
|
|
+ let nameButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ nameButton.setTitle("昵称", for: UIControl.State.normal)
|
|
|
+ nameButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
+ nameButton.titleLabel?.font = kBoldFont18
|
|
|
+ nameButton.alpha = 0
|
|
|
+ return nameButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var navigationBgView: UIView = {
|
|
|
+ let navigationBgView = UIView()
|
|
|
+ navigationBgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.5)
|
|
|
+ navigationBgView.alpha = 0
|
|
|
+ return navigationBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ //1.初始化JXSegmentedView
|
|
|
+ lazy var segmentedView: JXSegmentedView = {
|
|
|
+ let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: CGFloat(JXheightForHeaderInSection)))
|
|
|
+ segmentedView.delegate = self
|
|
|
+ segmentedView.dataSource = segmentedDataSource
|
|
|
+ segmentedView.contentScrollView = pagingView.listContainerView.collectionView
|
|
|
+ return segmentedView
|
|
|
+ }()
|
|
|
+
|
|
|
+ //2.初始化dataSource
|
|
|
+ lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
|
|
|
+ let segmentedDataSource = JXSegmentedTitleDataSource()
|
|
|
+ segmentedDataSource.isTitleColorGradientEnabled = true
|
|
|
+ segmentedDataSource.isItemSpacingAverageEnabled = true
|
|
|
+ segmentedDataSource.isTitleZoomEnabled = true
|
|
|
+ segmentedDataSource.titleNormalColor = k999999Color
|
|
|
+ segmentedDataSource.titleSelectedColor = k333333Color
|
|
|
+ segmentedDataSource.titleNormalFont = kRegularFont14!
|
|
|
+ segmentedDataSource.titleSelectedFont = kBoldFont16
|
|
|
+
|
|
|
+ //reloadData(selectedIndex:)方法一定要调用,方法内部会刷新数据源数组
|
|
|
+ segmentedDataSource.reloadData(selectedIndex: 0)
|
|
|
+ return segmentedDataSource
|
|
|
+ }()
|
|
|
+ //3.初始化指示器indicator
|
|
|
+ lazy var indicator: JXSegmentedIndicatorLineView = {
|
|
|
+ let indicator = JXSegmentedIndicatorLineView()
|
|
|
+ indicator.indicatorColor = k333333Color
|
|
|
+ indicator.indicatorHeight = 4
|
|
|
+ indicator.indicatorWidth = 22
|
|
|
+ return indicator
|
|
|
+ }()
|
|
|
+
|
|
|
+ //4.pagingView
|
|
|
+ lazy var pagingView: JXPagingView = {
|
|
|
+ let pagingView = JXPagingView(delegate: self)
|
|
|
+ return pagingView
|
|
|
+ }()
|
|
|
+ // 5.头部headerView
|
|
|
+ lazy var otherHeaderContainerView: UIView = {
|
|
|
+ let otherHeaderContainerView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: CGFloat(JXTableHeaderViewHeight)))
|
|
|
+ return otherHeaderContainerView
|
|
|
+ }()
|
|
|
+
|
|
|
+ /// 6.包含头部
|
|
|
+ lazy var otherHeaderView: OtherPersonalCenterHeaderView = {
|
|
|
+ var otherHeaderView = OtherPersonalCenterHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: CGFloat(JXTableHeaderViewHeight)))
|
|
|
+ return otherHeaderView
|
|
|
+ }()
|
|
|
+
|
|
|
+ override func viewDidLayoutSubviews() {
|
|
|
+ super.viewDidLayoutSubviews()
|
|
|
+ pagingView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
- /*
|
|
|
- // MARK: - Navigation
|
|
|
-
|
|
|
- // In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
- // Get the new view controller using segue.destination.
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
+extension OtherPersonalCenterViewController : JXSegmentedViewDelegate {
|
|
|
+ //点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,而不关心具体是点击还是滚动选中的情况。
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
|
|
|
+ self.otherPersonalCenterVCType = index
|
|
|
}
|
|
|
- */
|
|
|
+
|
|
|
+ // 点击选中的情况才会调用该方法
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // 滚动选中的情况才会调用该方法
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
|
|
|
+ }
|
|
|
+
|
|
|
+ // 正在滚动中的回调
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 是否允许点击选中目标index的item
|
|
|
+ func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+extension OtherPersonalCenterViewController: JXPagingViewDelegate {
|
|
|
+
|
|
|
+ func tableHeaderViewHeight(in pagingView: JXPagingView) -> Int {
|
|
|
+ return JXTableHeaderViewHeight
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableHeaderView(in pagingView: JXPagingView) -> UIView {
|
|
|
+ return otherHeaderContainerView
|
|
|
+ }
|
|
|
+
|
|
|
+ func heightForPinSectionHeader(in pagingView: JXPagingView) -> Int {
|
|
|
+ return JXheightForHeaderInSection
|
|
|
+ }
|
|
|
+
|
|
|
+ func viewForPinSectionHeader(in pagingView: JXPagingView) -> UIView {
|
|
|
+ pagingView.pinSectionHeaderVerticalOffset = kNavBarTotalHeight
|
|
|
+ return segmentedView
|
|
|
+ }
|
|
|
+
|
|
|
+ func numberOfLists(in pagingView: JXPagingView) -> Int {
|
|
|
+ return cmsTemplateTitles.count
|
|
|
+ }
|
|
|
+
|
|
|
+ func pagingView(_ pagingView: JXPagingView, initListAtIndex index: Int) -> JXPagingViewListViewDelegate {
|
|
|
+ let list = PersonViewUserAndOtherListView()
|
|
|
+ return list
|
|
|
+ }
|
|
|
+
|
|
|
+ func mainTableViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
+ otherHeaderView.personViewUserAndOtherHeaderView.scrollViewDidScroll(contentOffsetY: scrollView.contentOffset.y)
|
|
|
+
|
|
|
+ let offsetY = scrollView.contentOffset.y
|
|
|
+ if (offsetY > kSafeStatusBarHeight) {
|
|
|
+ let alpha = (offsetY - kSafeStatusBarHeight) / CGFloat(kNavBarTotalHeight)
|
|
|
+ navigationBar.wr_setBackgroundAlpha(alpha: alpha)
|
|
|
+ avatarButton.alpha = alpha
|
|
|
+ nameButton.alpha = alpha
|
|
|
+ navigationBgView.alpha = alpha
|
|
|
+
|
|
|
+ } else {
|
|
|
+ navigationBar.wr_setBackgroundAlpha(alpha: 0)
|
|
|
+ avatarButton.alpha = 0
|
|
|
+ nameButton.alpha = 0
|
|
|
+ navigationBgView.alpha = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|