Skip to content

Commit

Permalink
网络架构以及首页布局
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTXBEST committed Jul 6, 2017
1 parent 8c58e69 commit ffd36a1
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 6 deletions.
8 changes: 8 additions & 0 deletions DanTangSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
271D42F71F0CCD4600E04A82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 271D42F61F0CCD4600E04A82 /* Assets.xcassets */; };
271D42F91F0CE0C500E04A82 /* NetworkTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271D42F81F0CE0C500E04A82 /* NetworkTool.swift */; };
271D42FB1F0CE45800E04A82 /* TXHomeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271D42FA1F0CE45800E04A82 /* TXHomeModel.swift */; };
27DD2DBB1F0DD2FF009659ED /* TXHomeTopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DD2DBA1F0DD2FF009659ED /* TXHomeTopModel.swift */; };
27DD2DBD1F0E00FB009659ED /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DD2DBC1F0E00FB009659ED /* UIView+Extension.swift */; };
27E00AAD1F0C95E800B010C4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E00AAC1F0C95E800B010C4 /* AppDelegate.swift */; };
27E00AAF1F0C95E800B010C4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E00AAE1F0C95E800B010C4 /* ViewController.swift */; };
27E00AB21F0C95E800B010C4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 27E00AB01F0C95E800B010C4 /* Main.storyboard */; };
Expand Down Expand Up @@ -50,6 +52,8 @@
271D42F61F0CCD4600E04A82 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
271D42F81F0CE0C500E04A82 /* NetworkTool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTool.swift; sourceTree = "<group>"; };
271D42FA1F0CE45800E04A82 /* TXHomeModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXHomeModel.swift; sourceTree = "<group>"; };
27DD2DBA1F0DD2FF009659ED /* TXHomeTopModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXHomeTopModel.swift; sourceTree = "<group>"; };
27DD2DBC1F0E00FB009659ED /* UIView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = "<group>"; };
27E00AA91F0C95E800B010C4 /* DanTangSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DanTangSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
27E00AAC1F0C95E800B010C4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
27E00AAE1F0C95E800B010C4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -177,6 +181,7 @@
isa = PBXGroup;
children = (
27E00AF11F0CB6CB00B010C4 /* UIColor+Extension.swift */,
27DD2DBC1F0E00FB009659ED /* UIView+Extension.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -242,6 +247,7 @@
isa = PBXGroup;
children = (
271D42FA1F0CE45800E04A82 /* TXHomeModel.swift */,
27DD2DBA1F0DD2FF009659ED /* TXHomeTopModel.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -527,11 +533,13 @@
27E00AAF1F0C95E800B010C4 /* ViewController.swift in Sources */,
27E00B0A1F0CB84E00B010C4 /* MineVC.swift in Sources */,
27E00B081F0CB80400B010C4 /* HomeVC.swift in Sources */,
27DD2DBD1F0E00FB009659ED /* UIView+Extension.swift in Sources */,
27E00AEF1F0CB6B200B010C4 /* TXTabBarController.swift in Sources */,
271D42F91F0CE0C500E04A82 /* NetworkTool.swift in Sources */,
27E00AAD1F0C95E800B010C4 /* AppDelegate.swift in Sources */,
271D42FB1F0CE45800E04A82 /* TXHomeModel.swift in Sources */,
27E00B141F0CCBC700B010C4 /* TXNavigationController.swift in Sources */,
27DD2DBB1F0DD2FF009659ED /* TXHomeTopModel.swift in Sources */,
27E00AF21F0CB6CB00B010C4 /* UIColor+Extension.swift in Sources */,
27E00B0C1F0CB88F00B010C4 /* ProductVC.swift in Sources */,
27E00AEE1F0CB6B200B010C4 /* TXBaseViewController.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,38 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DanTangSwift/Tools/NetworkTool.swift"
timestampString = "521003319.441992"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
landmarkName = "loadHomeInfo(id:finished:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DanTangSwift/Tools/NetworkTool.swift"
timestampString = "521003319.441992"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "69"
endingLineNumber = "69"
landmarkName = "loadHomeInfo(id:finished:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
108 changes: 108 additions & 0 deletions DanTangSwift/Extension/UIView+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// UIView+Extension.swift
// DanTangSwift
//
// Created by 赵天旭 on 2017/7/6.
// Copyright © 2017年 ZTX. All rights reserved.
//

import UIKit

extension UIView {
/// 裁剪 view 的圆角
func clipRectCorner(direction: UIRectCorner, cornerRadius: CGFloat) {
let cornerSize = CGSize(width: cornerRadius, height: cornerRadius)
let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: direction, cornerRadii: cornerSize)
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.cgPath
layer.addSublayer(maskLayer)
layer.mask = maskLayer
}

/// x
var x: CGFloat {
get {
return frame.origin.x
}
set(newValue) {
var tempFrame: CGRect = frame
tempFrame.origin.x = newValue
frame = tempFrame
}
}

/// y
var y: CGFloat {
get {
return frame.origin.y
}
set(newValue) {
var tempFrame: CGRect = frame
tempFrame.origin.y = newValue
frame = tempFrame
}
}

/// height
var height: CGFloat {
get {
return frame.size.height
}
set(newValue) {
var tempFrame: CGRect = frame
tempFrame.size.height = newValue
frame = tempFrame
}
}

/// width
var width: CGFloat {
get {
return frame.size.width
}
set(newValue) {
var tempFrame: CGRect = frame
tempFrame.size.width = newValue
frame = tempFrame
}
}

/// size
var size: CGSize {
get {
return frame.size
}
set(newValue) {
var tempFrame: CGRect = frame
tempFrame.size = newValue
frame = tempFrame
}
}

/// centerX
var centerX: CGFloat {
get {
return center.x
}
set(newValue) {
var tempCenter: CGPoint = center
tempCenter.x = newValue
center = tempCenter
}
}

/// centerY
var centerY: CGFloat {
get {
return center.y
}
set(newValue) {
var tempCenter: CGPoint = center
tempCenter.y = newValue
center = tempCenter;
}
}


}
79 changes: 77 additions & 2 deletions DanTangSwift/Home/Controller/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import UIKit

class HomeVC: TXBaseViewController {
var channels = [TXHomeTopModel]()
//选中的标签
var selectButton = UIButton()
//底部红色指示器
weak var indicatorView = UIView()

override func viewDidLoad() {
super.viewDidLoad()
initNav()
requestData()
initTitlesView()
// Do any additional setup after loading the view.
}

Expand All @@ -24,16 +28,87 @@ class HomeVC: TXBaseViewController {
}

private func requestData() {

weak var weakSelf = self
NetworkTool.shared.loadHomeTopData { (datas) in
weakSelf?.channels = datas
weakSelf?.initTitlesView()
}
}

// 顶部标签
private func initTitlesView() {
// 顶部view
let bgView = UIView()
bgView.frame=CGRect(x: 0, y: kTitlesViewY, width:KScreenWidth, height: kTitlesViewH)
view.addSubview(bgView)

//标签view
let titlesView = UIView()
titlesView.frame=CGRect(x: 0, y: 0, width:KScreenWidth-kTitlesViewH, height: kTitlesViewH)
titlesView.backgroundColor=TXGlobalColor()
bgView.addSubview(titlesView)

//右侧箭头
let arrowBtn = UIButton()
arrowBtn.frame=CGRect(x: KScreenWidth-kTitlesViewH, y: 0, width: kTitlesViewH, height: kTitlesViewH)
arrowBtn.setImage(UIImage(named: "arrow_index_down_8x4_"), for: .normal)
arrowBtn.setImage(UIImage(named: "arrow_index_up_8x4_"), for: .selected)
arrowBtn.addTarget(self, action: #selector(arrowBtnClick(sender:)), for: .touchUpInside)
bgView.addSubview(arrowBtn)

//底部滑动view
let indicatorView = UIView()
indicatorView.backgroundColor = TXGlobalRedColor()
indicatorView.height = 2
indicatorView.y = kTitlesViewH - 2
self.indicatorView = indicatorView
indicatorView.tag = -1

let count = channels.count
let width = titlesView.width / CGFloat(count)
let height = titlesView.height

for index in 0..<count {
let channel = channels[index]
let button = UIButton()
button.height = height
button.width = width
button.x = CGFloat(index)*width;
button.tag = index
button.setTitle(channel.name, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
button.setTitleColor(UIColor.gray, for: .normal)
button.setTitleColor(TXGlobalRedColor(), for: .disabled)
button.addTarget(self, action: #selector(titlesClick(button:)), for: .touchUpInside)
titlesView.addSubview(button)

if index==0 {
button.isEnabled = false
selectButton = button
indicatorView.width = button.width
indicatorView.centerX = button.centerX
}
}
titlesView.addSubview(indicatorView)
}

func titlesClick(button:UIButton) {
selectButton.isEnabled = true
button.isEnabled = false
selectButton = button
UIView.animate(withDuration: 0.25) {
self.indicatorView?.width = self.selectButton.width
self.indicatorView?.centerX = self.selectButton.centerX
}
}

func rightButtonClick() {
print("123")
}

func arrowBtnClick(sender:UIButton){
sender.isSelected = !sender.isSelected
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
Expand Down
21 changes: 21 additions & 0 deletions DanTangSwift/Home/Model/TXHomeTopModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// TXHomeTopModel.swift
// DanTangSwift
//
// Created by 赵天旭 on 2017/7/6.
// Copyright © 2017年 ZTX. All rights reserved.
//

import UIKit

class TXHomeTopModel: NSObject {
var editable: Bool?
var id: Int?
var name: String?

init(dict: [String: AnyObject]) {
id = dict["id"] as? Int
name = dict["name"] as? String
editable = dict["editable"] as? Bool
}
}
5 changes: 5 additions & 0 deletions DanTangSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
Loading

0 comments on commit ffd36a1

Please sign in to comment.