From 383ba286efdc4532a83f38d20312d46f95ed5a47 Mon Sep 17 00:00:00 2001 From: stan <3421902@qq.com> Date: Tue, 20 Dec 2016 15:33:20 +0800 Subject: [PATCH] fix some thing --- .swift-version | 1 + GrandMenu.podspec | 4 +- GrandMenu/GrandMenu.swift | 2 +- GrandMenu/GrandMenuTable.swift | 57 +++++++++++++----- GrandMenuDemo/.DS_Store | Bin 6148 -> 6148 bytes .../GrandMenuDemo.xcodeproj/project.pbxproj | 10 ++- 6 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..9f55b2c --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0 diff --git a/GrandMenu.podspec b/GrandMenu.podspec index d87b084..b5c752d 100644 --- a/GrandMenu.podspec +++ b/GrandMenu.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "GrandMenu" - s.version = "1.0.0" + s.version = "1.0.1" s.summary = "GrandMenu is a powerful and simple Menu" # This description is used to generate tags and improve search results. @@ -80,7 +80,7 @@ Pod::Spec.new do |s| # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/DuckDeck/GrandMenu.git", :tag => "1.0.0" } + s.source = { :git => "https://github.com/DuckDeck/GrandMenu.git", :tag => "1.0.1" } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # diff --git a/GrandMenu/GrandMenu.swift b/GrandMenu/GrandMenu.swift index 734a7e5..541586d 100644 --- a/GrandMenu/GrandMenu.swift +++ b/GrandMenu/GrandMenu.swift @@ -167,7 +167,7 @@ open class GrandMenu: UIView,GraneMenuItemDelegate { item.delegate = weakSelf var itemWidth = GrandMenuItem.getTitleWidth(title,fontSize: item.fontSize) if averageManu{ - itemWidth = Float(UIScreen.main.bounds.width / CGFloat(arrItemsTitle!.count)) + itemWidth = Float(frame.size.width / CGFloat(arrItemsTitle!.count)) } item.frame = CGRect(x: CGFloat(x), y: CGFloat(0), width: CGFloat(itemWidth), height: scrollView!.frame.height) item.title = title diff --git a/GrandMenu/GrandMenuTable.swift b/GrandMenu/GrandMenuTable.swift index 986ab4c..3ac6bae 100644 --- a/GrandMenu/GrandMenuTable.swift +++ b/GrandMenu/GrandMenuTable.swift @@ -9,14 +9,26 @@ import UIKit open class GrandMenuTable: UIView,UITableViewDataSource,UITableViewDelegate { - open var tb:UITableView? - fileprivate var arrViewControllers:[UIViewController]? - fileprivate var arrViews:[UIView]? - open var scrollToIndex:((_ index:Int)->Void)? + open var tb:UITableView? + fileprivate var arrViewControllers:[UIViewController]? + fileprivate var arrViews:[UIView]? + open var cellBgColor = UIColor.clear + public var itemCount:Int{ + get{ + if arrViewControllers != nil{ + return arrViewControllers!.count + } + else if arrViews != nil{ + return arrViews!.count + } + return 0 + } + } + open var scrollToIndex:((_ index:Int)->Void)? fileprivate override init(frame: CGRect) { super.init(frame: frame) } - public convenience init(frame:CGRect,arrViewControllers:[UIViewController]){ + public convenience init(frame:CGRect,arrViewControllers:[UIViewController]){ self.init(frame:frame) self.arrViewControllers = arrViewControllers tb = UITableView() @@ -48,7 +60,11 @@ open class GrandMenuTable: UIView,UITableViewDataSource,UITableViewDelegate { addSubview(tb!) } - + public func addController(controller:UIViewController){ + arrViewControllers?.append(controller) + let index = IndexPath(row: arrViewControllers!.count - 1, section: 0) + tb?.reloadRows(at: [index], with: .none) + } required public init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") @@ -71,14 +87,25 @@ open class GrandMenuTable: UIView,UITableViewDataSource,UITableViewDelegate { cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "GrandCell") cell?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI_2)) cell?.selectionStyle = .none + cell?.backgroundColor = cellBgColor cell?.contentView.backgroundColor = UIColor.clear } - if arrViewControllers != nil{ + if arrViewControllers != nil { + if cell!.contentView.subviews.count > 0{ + for v in cell!.contentView.subviews{ + v.removeFromSuperview() + } + } let v = arrViewControllers![(indexPath as NSIndexPath).row] v.view.frame = cell!.bounds cell?.contentView.addSubview(v.view) } - else if arrViews != nil{ + else if arrViews != nil { + if cell!.contentView.subviews.count > 0{ + for v in cell!.contentView.subviews{ + v.removeFromSuperview() + } + } let v = arrViews![(indexPath as NSIndexPath).row] cell?.contentView.addSubview(v) } @@ -96,11 +123,11 @@ open class GrandMenuTable: UIView,UITableViewDataSource,UITableViewDelegate { } } - open func selectIndex(_ index:Int){ - weak var weakSelf = self - UIView.animate(withDuration: 0.3, animations: { () -> Void in - weakSelf?.tb?.scrollToRow(at: IndexPath(row: index, section: 0), at: .none, animated: true) - }) -} - + open func selectIndex(_ index:Int){ + weak var weakSelf = self + UIView.animate(withDuration: 0.3, animations: { () -> Void in + weakSelf?.tb?.scrollToRow(at: IndexPath(row: index, section: 0), at: .none, animated: true) + }) + } + } diff --git a/GrandMenuDemo/.DS_Store b/GrandMenuDemo/.DS_Store index bdc5dab754e8cc23d6164935a743d490eb4d2922..94045016d861381ca9f2631e5726524cf0eee346 100644 GIT binary patch delta 51 ycmZoMXffE}!^G5YHhBV*36G0QN@+=BFTpu5Shki2?xByAt~V delta 51 wcmZoMXffE}!^G6dF?j-$36G0QN@+