Skip to content

Commit 67060f5

Browse files
author
lilin1
committed
segmentCtl不在绑定ViewController
1 parent ecd6a32 commit 67060f5

File tree

20 files changed

+219
-235
lines changed

20 files changed

+219
-235
lines changed

LLSegmentViewController.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,14 @@
746746
buildSettings = {
747747
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
748748
CODE_SIGN_STYLE = Automatic;
749-
DEVELOPMENT_TEAM = AT942ZRU45;
749+
DEVELOPMENT_TEAM = 8XN9KLEGU7;
750750
INFOPLIST_FILE = LLSegmentViewController/Info.plist;
751751
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
752752
LD_RUNPATH_SEARCH_PATHS = (
753753
"$(inherited)",
754754
"@executable_path/Frameworks",
755755
);
756-
PRODUCT_BUNDLE_IDENTIFIER = com.qianhaishouhui.LLSegmentViewController;
756+
PRODUCT_BUNDLE_IDENTIFIER = com.qianhaishouhui.LLSegmentViewController12;
757757
PRODUCT_NAME = "$(TARGET_NAME)";
758758
SWIFT_VERSION = 4.2;
759759
TARGETED_DEVICE_FAMILY = "1,2";
@@ -766,14 +766,14 @@
766766
buildSettings = {
767767
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
768768
CODE_SIGN_STYLE = Automatic;
769-
DEVELOPMENT_TEAM = AT942ZRU45;
769+
DEVELOPMENT_TEAM = 8XN9KLEGU7;
770770
INFOPLIST_FILE = LLSegmentViewController/Info.plist;
771771
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
772772
LD_RUNPATH_SEARCH_PATHS = (
773773
"$(inherited)",
774774
"@executable_path/Frameworks",
775775
);
776-
PRODUCT_BUNDLE_IDENTIFIER = com.qianhaishouhui.LLSegmentViewController;
776+
PRODUCT_BUNDLE_IDENTIFIER = com.qianhaishouhui.LLSegmentViewController12;
777777
PRODUCT_NAME = "$(TARGET_NAME)";
778778
SWIFT_VERSION = 4.2;
779779
TARGETED_DEVICE_FAMILY = "1,2";

LLSegmentViewController/Example/CustomItemView/AttributeItemView.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ class AttributeItemView: LLSegmentBaseItemView {
3838
attributedText.addAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 15)], range: NSRange.init(location: 0, length: contentStr.count))
3939
titleLabel.attributedText = attributedText
4040
}
41-
42-
//方式二:ctl转化为自己的viewControler,
43-
// if let ctl = associateViewCtl as? CustomViewControler{
44-
// let model = ctl.model
45-
// }
46-
4741
}
4842

4943
override func itemWidth() -> CGFloat {

LLSegmentViewController/Example/CustomTableViewController/SimpleTabViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class SimpleTabViewController: LLSegmentViewController {
2525
}
2626

2727
func loadCtls() {
28-
let test1Ctl = factoryCtl(title: "微信", imageName: "tabbar_mainframe", selectedImageNameStr: "tabbar_mainframeHL")
28+
let test1Ctl = TestViewController(title: "微信", imageName: "tabbar_mainframe", selectedImageNameStr: "tabbar_mainframeHL")
2929
test1Ctl.tabBarItem.badgeValue = "10"
3030

31-
let test2Ctl = factoryCtl(title: "通讯录", imageName: "tabbar_contacts", selectedImageNameStr: "tabbar_contactsHL")
31+
let test2Ctl = TestViewController(title: "通讯录", imageName: "tabbar_contacts", selectedImageNameStr: "tabbar_contactsHL")
3232
test2Ctl.tabBarItem.badgeValue = nil
3333

34-
let test3Ctl = factoryCtl(title: "发现", imageName: "tabbar_discover1", selectedImageNameStr: "tabbar_discoverHL")
34+
let test3Ctl = TestViewController(title: "发现", imageName: "tabbar_discover1", selectedImageNameStr: "tabbar_discoverHL")
3535
test3Ctl.tabBarItem.badgeValue = LLSegmentRedBadgeValue
3636

37-
let test4Ctl = factoryCtl(title: "", imageName: "tabbar_me", selectedImageNameStr: "tabbar_meHL")
37+
let test4Ctl = TestViewController(title: "", imageName: "tabbar_me", selectedImageNameStr: "tabbar_meHL")
3838
let ctls = [test1Ctl,test2Ctl,test3Ctl,test4Ctl]
3939
reloadViewControllers(ctls:ctls)
4040
}

LLSegmentViewController/Example/CustomTableViewController/SinaViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class SinaViewController: LLSegmentViewController {
2424
}
2525

2626
func loadCtls() {
27-
let test1Ctl = factoryCtl(title: "首页", imageName: "tabbar_home", selectedImageNameStr: "tabbar_home_selected")
27+
let test1Ctl = TestViewController(title: "首页", imageName: "tabbar_home", selectedImageNameStr: "tabbar_home_selected")
2828
test1Ctl.tabBarItem.badgeValue = "10"
2929

30-
let test2Ctl = factoryCtl(title: "消息", imageName: "tabbar_message_center", selectedImageNameStr: "tabbar_message_center_selected")
30+
let test2Ctl = TestViewController(title: "消息", imageName: "tabbar_message_center", selectedImageNameStr: "tabbar_message_center_selected")
3131

32-
let test3Ctl = factoryCtl(title: "发现", imageName: "tabbar_discover", selectedImageNameStr: "tabbar_discover_selected")
32+
let test3Ctl = TestViewController(title: "发现", imageName: "tabbar_discover", selectedImageNameStr: "tabbar_discover_selected")
3333
test3Ctl.tabBarItem.badgeValue = LLSegmentRedBadgeValue
3434

35-
let test4Ctl = factoryCtl(title: "我的", imageName: "tabbar_profile", selectedImageNameStr: "tabbar_profile_selected")
35+
let test4Ctl = TestViewController(title: "我的", imageName: "tabbar_profile", selectedImageNameStr: "tabbar_profile_selected")
3636

3737
let ctls = [test1Ctl,test2Ctl,test3Ctl,test4Ctl]
3838
reloadViewControllers(ctls:ctls)

LLSegmentViewController/Example/DetailViewController/PersonDetailViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class PersonDetailViewController: LLSegmentViewController {
3434
}
3535

3636
func loadCtls() {
37-
let test1Ctl = factoryCtl(title: "能力", imageName: "", selectedImageNameStr: "")
38-
let test2Ctl = factoryCtl(title: "爱好", imageName: "", selectedImageNameStr: "")
39-
let test3Ctl = factoryCtl(title: "队友", imageName: "", selectedImageNameStr: "")
37+
let test1Ctl = TestViewController.init(title: "能力", imageName: "", selectedImageNameStr: "")
38+
let test2Ctl = TestViewController.init(title: "爱好", imageName: "", selectedImageNameStr: "")
39+
let test3Ctl = TestViewController.init(title: "队友", imageName: "", selectedImageNameStr: "")
4040
let ctls = [test1Ctl,test2Ctl,test3Ctl]
4141
reloadViewControllers(ctls:ctls)
4242
}

LLSegmentViewController/Example/IndicatorViewController/BadgeValueViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BadgeValueViewController: LLSegmentViewController {
5252
class TestBadgeValueViewController: UIViewController {
5353
override func viewDidLoad() {
5454
super.viewDidLoad()
55-
self.view.backgroundColor = LLRandomRGB()
55+
self.view.backgroundColor = UIColor.init(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1)
5656
}
5757
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
5858
super.touchesEnded(touches, with: event)

LLSegmentViewController/Example/SpecialViewController/TitleImageItemViewController.swift

Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,31 @@ class TitleImageItemViewController: LLSegmentViewController {
2525

2626
func loadCtls(style:LLTitleImageButtonStyle?) {
2727
var ctls = [UIViewController]()
28-
let models = getModels(style: style)
29-
for model in models {
30-
let ctl = TitleImageViewController()
28+
let margin: CGFloat = 5
29+
let datas:[(title:String,imageStr:String,style:LLTitleImageButtonStyle)] = [
30+
("螃蟹","watermelon",LLTitleImageButtonStyle.titleTop(margin: margin)),
31+
("麻辣小龙虾","lobster",LLTitleImageButtonStyle.titleRight(margin: margin)),
32+
("苹果","grape", LLTitleImageButtonStyle.titleLeft(margin: margin)),
33+
("营养胡萝卜","crab",LLTitleImageButtonStyle.titleBottom(margin: margin)),
34+
("葡萄","carrot",LLTitleImageButtonStyle.titleEmty),
35+
("美味西瓜","apple",LLTitleImageButtonStyle.titleOnly),]
36+
for (title,imageStr, diyStyle) in datas {
37+
let ctl = TestViewController.init()
3138
ctl.showTableView = true
32-
ctl.model = model
33-
ctl.title = model.title
39+
let tabBarItem = LLSegmentItemTitleImageTabBarItem.init(
40+
title: title,
41+
image: UIImage(named: imageStr),
42+
selectedImage: UIImage(named: imageStr + "_selected"))
43+
if let currentStyle = style {
44+
tabBarItem.style = currentStyle
45+
}else{
46+
tabBarItem.style = diyStyle
47+
}
48+
49+
tabBarItem.setImageBlock = { (imageView,isSelected,tabBarItem) in
50+
imageView.image = isSelected ? tabBarItem.selectedImage : tabBarItem.image
51+
}
52+
ctl.tabBarItem = tabBarItem
3453
ctls.append(ctl)
3554
}
3655
reloadViewControllers(ctls:ctls)
@@ -62,26 +81,7 @@ class TitleImageItemViewController: LLSegmentViewController {
6281

6382

6483

65-
66-
67-
class TitleImageViewController: TestViewController,LLSegmentItemTitleImageViewProtocol {
68-
func refreshWhenPercentChange(titleLabel:UILabel,imageView: UIImageView, percent: CGFloat) {
69-
if percent < 0.5 {
70-
titleLabel.textColor = UIColor.lightGray
71-
imageView.image = UIImage.init(named: model.imgeStr)
72-
}else {
73-
titleLabel.textColor = UIColor.black
74-
imageView.image = UIImage.init(named: model.imgeStr + "_selected")
75-
}
76-
}
77-
78-
var model:LLTitleImageModel!
79-
}
80-
81-
82-
83-
84-
84+
//选择某种样式
8585
class ChooseTitleImageStyleViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
8686
typealias chooseStyleBlockDefine = (LLTitleImageButtonStyle?)->Void
8787
var chooseStyleBlock:chooseStyleBlockDefine?
@@ -94,9 +94,19 @@ class ChooseTitleImageStyleViewController: UIViewController,UITableViewDataSourc
9494
("混合",nil)]
9595
override func viewDidLoad() {
9696
super.viewDidLoad()
97-
let tableView = addTableView()
97+
initTableView()
98+
}
99+
100+
func initTableView() {
101+
let tableView = UITableView(frame: view.bounds, style: .plain)
98102
tableView.delegate = self
99103
tableView.dataSource = self
104+
tableView.backgroundColor = UIColor.white
105+
tableView.tableFooterView = UIView()
106+
tableView.frame = view.bounds
107+
tableView.autoresizingMask = [.flexibleHeight,.flexibleWidth]
108+
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
109+
view.addSubview(tableView)
100110
}
101111

102112
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -108,48 +118,10 @@ class ChooseTitleImageStyleViewController: UIViewController,UITableViewDataSourc
108118
cell.textLabel?.text = dataArr[indexPath.row].title
109119
return cell
110120
}
121+
111122
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
112123
let data = dataArr[indexPath.row]
113124
chooseStyleBlock?(data.style)
114125
self.navigationController?.popViewController(animated: true)
115126
}
116127
}
117-
118-
119-
120-
121-
func getModels(style:LLTitleImageButtonStyle?)->[LLTitleImageModel] {
122-
let datas:[(title:String,imageStr:String)] = [
123-
("螃蟹","watermelon"),
124-
("麻辣小龙虾","lobster"),
125-
("苹果","grape"),
126-
("营养胡萝卜","crab"),
127-
("葡萄","carrot"),
128-
("美味西瓜","apple"),
129-
("香蕉","grape")]
130-
var models = [LLTitleImageModel]()
131-
let margin:CGFloat = 2
132-
for (index,data) in datas.enumerated() {
133-
var newStyle = LLTitleImageButtonStyle.titleEmty
134-
if style != nil {
135-
newStyle = style!
136-
}else{
137-
if index == 0 {
138-
newStyle = LLTitleImageButtonStyle.titleTop(margin: margin)
139-
}else if index == 1{
140-
newStyle = LLTitleImageButtonStyle.titleRight(margin: margin)
141-
}else if index == 2{
142-
newStyle = LLTitleImageButtonStyle.titleLeft(margin: margin)
143-
}else if index == 3{
144-
newStyle = LLTitleImageButtonStyle.titleBottom(margin: margin)
145-
}else if index == 4{
146-
newStyle = LLTitleImageButtonStyle.titleEmty
147-
}else if index == 5{
148-
newStyle = LLTitleImageButtonStyle.titleOnly
149-
}
150-
}
151-
let model = LLTitleImageModel(title: data.title, imgeStr: data.imageStr, style: newStyle)
152-
models.append(model)
153-
}
154-
return models
155-
}

LLSegmentViewController/LLSegmentViewController/LLPageView/LLContainerScrollView.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ import UIKit
1818
open class LLContainerScrollView: UIScrollView {
1919
public var paralaxHeader = LLSubViewsLayoutInfo()
2020
internal weak var dragDeleage:LLContainerScrollViewDagDelegate?
21-
private var observedViews = [UIScrollView]()
2221

22+
private var observedViews = [UIScrollView]()
2323
private let observerKeyPath = "contentOffset"
2424
private let observerOptions:NSKeyValueObservingOptions = [.old,.new]
2525
private var observerContext = 0
2626

2727
private var isObserving = true
2828
private var lock = false
2929
private var tapAtScrollerToTopLock = false
30+
3031
private var safeBottomMargin = mSafeBottomMargin()
3132
override init(frame: CGRect) {
3233
super.init(frame: frame)
@@ -219,22 +220,27 @@ extension LLContainerScrollView : UIScrollViewDelegate {
219220
}
220221

221222
extension LLContainerScrollView : UIGestureRecognizerDelegate {
223+
//两个scrollView同时滚动
222224
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
223225
if otherGestureRecognizer.view == self {
224226
return false
225227
}
226228

229+
// Consider scroll view pan only
230+
guard let scrollView = otherGestureRecognizer.view as? UIScrollView else {
231+
return false
232+
}
227233
guard let otherGestureRecognizer = otherGestureRecognizer as? UIPanGestureRecognizer else {
228234
return false
229235
}
236+
230237

238+
//横行滚动禁止联动
231239
let velocity = otherGestureRecognizer.velocity(in: self)
232240
if abs(velocity.x) > abs(velocity.y) {
233241
return false
234242
}
235243

236-
// Consider scroll view pan only
237-
guard let scrollView = otherGestureRecognizer.view as? UIScrollView else { return false }
238244

239245
// Tricky case: UITableViewWrapperView
240246
if scrollView.superview?.isKind(of: UITableView.classForCoder()) == true {

LLSegmentViewController/LLSegmentViewController/LLSegmentViewController.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class LLSubViewsLayoutInfo:NSObject{
3939

4040
open class LLSegmentViewController: UIViewController {
4141
public let layoutInfo = LLSubViewsLayoutInfo()
42-
public let segmentCtlView = LLSegmentedControl(frame: CGRect.zero, titles: [String]())
42+
public let segmentCtlView = LLSegmentedControl(frame: CGRect.zero, tabBarItems: [UITabBarItem]())
4343
public let pageView:LLCtlPageView = LLCtlPageView(frame: CGRect.zero, ctls: [UIViewController]())
4444
public let containerScrView = LLContainerScrollView()
4545
public private (set) var ctls = [UIViewController]()
@@ -136,8 +136,8 @@ extension LLSegmentViewController{
136136
let title = ctl.ctlTitle()
137137
titles.append(title)
138138
}
139-
segmentCtlView.ctls = ctls
140-
segmentCtlView.titles = titles
139+
140+
segmentCtlView.tabBarItems = ctls.map({ $0.tabBarItem })
141141
segmentCtlView.reloadData()
142142

143143
pageView.reloadCurrentIndex(index: 0)
@@ -153,9 +153,8 @@ extension LLSegmentViewController{
153153
pageView.reloadCurrentIndex(index: itemIndex)
154154
pageView.reloadData()
155155

156-
segmentCtlView.titles.insert(ctl.ctlTitle(), at: index)
156+
segmentCtlView.tabBarItems.insert(ctl.tabBarItem, at: index)
157157
segmentCtlView.ctlViewStyle.defaultSelectedIndex = itemIndex
158-
segmentCtlView.ctls = ctls
159158
segmentCtlView.reloadData()
160159
}
161160
}

LLSegmentViewController/LLSegmentViewController/LLSegmentedControl/LLIndicatorView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,19 @@ extension LLIndicatorView{
216216
targetWidth = interpolationFrom(from: leftItemWidth, to: rightItemWidth, percent: rightItemView.percent)
217217
targetWidth -= 2*margin
218218
case .jdIqiyi(let baseWidth,let changeWidth):
219-
let percent = 1 - abs(0.5-leftItemView.percent)*2 //变化范围(0....1.....0)
219+
let newPercent = 1 - abs(0.5-leftItemView.percent)*2 //变化范围(0....1.....0)
220220
let minX = leftItemView.center.x - baseWidth/2
221221
let maxX = rightItemView.center.x - baseWidth/2
222-
targetWidth = percent * (maxX - minX - changeWidth) + baseWidth
222+
targetWidth = newPercent * (maxX - minX - changeWidth) + baseWidth
223223

224224
case .stationary(let baseWidth):
225225
targetWidth = baseWidth
226226
}
227227
var selfBounds = self.bounds
228228
selfBounds.size.width = targetWidth
229229
self.bounds = selfBounds
230-
delegate?.indicatorView?(indicatorView: self, percent: leftItemView.percent)
231230

231+
delegate?.indicatorView?(indicatorView: self, percent: leftItemView.percent)
232232
self.handleQQMsgStyle(leftItemView: leftItemView)
233233
}
234234

0 commit comments

Comments
 (0)