From 3e2e6c6467d5ef72ebc0fdaba1e7995ceafd8493 Mon Sep 17 00:00:00 2001 From: Nejc Date: Mon, 14 Nov 2016 15:23:57 +0100 Subject: [PATCH 1/7] no message --- .../MRTableViewCellCountScrollIndicator.swift | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift index 9c6501a..e7b7922 100644 --- a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift +++ b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift @@ -11,6 +11,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate private var dynamicUnpagedHeight:Bool = false var y:CGFloat = -1000 private var topConstraint : NSLayoutConstraint! + var rectHeight:CGFloat? public var opacity:CGFloat = 1 { didSet { @@ -31,6 +32,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate public init(tableView:UITableView) { self.tableView = tableView tableView.layoutIfNeeded() + self.rectHeight = self.tableView.frame.height super.init() scrollCountView.translatesAutoresizingMaskIntoConstraints = false tableView.addSubview(scrollCountView) @@ -48,6 +50,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate rightConstraint = NSLayoutConstraint(item: scrollCountView, attribute: .Trailing, relatedBy: .Equal, toItem: tableView, attribute: .Leading, multiplier: 1, constant: tableView.contentSize.width) tableView.addConstraint(rightConstraint) showCellScrollCount(false) + } public func showCellScrollCount(animated:Bool) { @@ -69,17 +72,26 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate func updateScrollPosition() { - //var currentCellRect:CGRect? + var percentage: CGFloat? + if let h = self.rectHeight { + percentage = (self.tableView.contentOffset.y)/(self.tableView.contentSize.height - h) + if (percentage < 0) { + percentage = 0 + } + + if let index = self.tableView.indexPathForRowAtPoint(CGPoint(x: 0, y: percentage!*self.tableView.contentSize.height)) { + scrollCountView.currentScrollCountNum = index.row + } + } + let indexPaths = tableView.indexPathsForVisibleRows var currentCellRect:CGRect? if let indexPaths = indexPaths { if indexPaths.count > 0 { currentCellRect = tableView.rectForRowAtIndexPath(indexPaths[0]) - scrollCountView.currentScrollCountNum = indexPaths[0].row } } - guard let currentCellRectu = currentCellRect else { return } @@ -116,24 +128,16 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate return } - let oneDistance = tableView.bounds.size.height / CGFloat(totalScrollCountNum) - let currentCellHeight = currentCellRectu.size.height - let currentCellOffset = currentCellRectu.origin.y - let currentOffset = tableView.contentOffset.y - - let dxp = (currentOffset - currentCellOffset)/currentCellHeight - let dx = dxp * oneDistance - - var finalY = tableView.contentOffset.y + ((tableView.bounds.size.height*CGFloat(scrollCountView.currentScrollCountNum)) / CGFloat(totalScrollCountNum)) + dx - - if (finalY < 0) { - finalY = 0 - } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { - finalY = tableView.contentSize.height - scrollCountViewHeight + if let p = percentage { + var finalY = tableView.contentSize.height * percentage! + + if (finalY < 0) { + finalY = 0 + } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { + finalY = tableView.contentSize.height - scrollCountViewHeight + } + topConstraint.constant = finalY } - - topConstraint.constant = finalY } } - } From 88eefd03c77fd18ff216889220632deb2deef43f Mon Sep 17 00:00:00 2001 From: Nejc Date: Mon, 14 Nov 2016 15:35:44 +0100 Subject: [PATCH 2/7] Revert "no message" This reverts commit 3e2e6c6467d5ef72ebc0fdaba1e7995ceafd8493. --- .../MRTableViewCellCountScrollIndicator.swift | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift index e7b7922..9c6501a 100644 --- a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift +++ b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift @@ -11,7 +11,6 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate private var dynamicUnpagedHeight:Bool = false var y:CGFloat = -1000 private var topConstraint : NSLayoutConstraint! - var rectHeight:CGFloat? public var opacity:CGFloat = 1 { didSet { @@ -32,7 +31,6 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate public init(tableView:UITableView) { self.tableView = tableView tableView.layoutIfNeeded() - self.rectHeight = self.tableView.frame.height super.init() scrollCountView.translatesAutoresizingMaskIntoConstraints = false tableView.addSubview(scrollCountView) @@ -50,7 +48,6 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate rightConstraint = NSLayoutConstraint(item: scrollCountView, attribute: .Trailing, relatedBy: .Equal, toItem: tableView, attribute: .Leading, multiplier: 1, constant: tableView.contentSize.width) tableView.addConstraint(rightConstraint) showCellScrollCount(false) - } public func showCellScrollCount(animated:Bool) { @@ -72,26 +69,17 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate func updateScrollPosition() { - var percentage: CGFloat? - if let h = self.rectHeight { - percentage = (self.tableView.contentOffset.y)/(self.tableView.contentSize.height - h) - if (percentage < 0) { - percentage = 0 - } - - if let index = self.tableView.indexPathForRowAtPoint(CGPoint(x: 0, y: percentage!*self.tableView.contentSize.height)) { - scrollCountView.currentScrollCountNum = index.row - } - } - + //var currentCellRect:CGRect? let indexPaths = tableView.indexPathsForVisibleRows var currentCellRect:CGRect? if let indexPaths = indexPaths { if indexPaths.count > 0 { currentCellRect = tableView.rectForRowAtIndexPath(indexPaths[0]) + scrollCountView.currentScrollCountNum = indexPaths[0].row } } + guard let currentCellRectu = currentCellRect else { return } @@ -128,16 +116,24 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate return } - if let p = percentage { - var finalY = tableView.contentSize.height * percentage! - - if (finalY < 0) { - finalY = 0 - } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { - finalY = tableView.contentSize.height - scrollCountViewHeight - } - topConstraint.constant = finalY + let oneDistance = tableView.bounds.size.height / CGFloat(totalScrollCountNum) + let currentCellHeight = currentCellRectu.size.height + let currentCellOffset = currentCellRectu.origin.y + let currentOffset = tableView.contentOffset.y + + let dxp = (currentOffset - currentCellOffset)/currentCellHeight + let dx = dxp * oneDistance + + var finalY = tableView.contentOffset.y + ((tableView.bounds.size.height*CGFloat(scrollCountView.currentScrollCountNum)) / CGFloat(totalScrollCountNum)) + dx + + if (finalY < 0) { + finalY = 0 + } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { + finalY = tableView.contentSize.height - scrollCountViewHeight } + + topConstraint.constant = finalY } } + } From 5d7643f6e4f30874829220f220bb664c4d0df5ab Mon Sep 17 00:00:00 2001 From: Nejc Date: Mon, 14 Nov 2016 16:08:15 +0100 Subject: [PATCH 3/7] 0.0.7 fix? --- MRTableViewCellCountScrollIndicator.podspec | 2 +- .../MRTableViewCellCountScrollIndicator.swift | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/MRTableViewCellCountScrollIndicator.podspec b/MRTableViewCellCountScrollIndicator.podspec index db3f7e1..a272fef 100644 --- a/MRTableViewCellCountScrollIndicator.podspec +++ b/MRTableViewCellCountScrollIndicator.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'MRTableViewCellCountScrollIndicator' - s.version = '0.0.6' + s.version = '0.0.7 s.summary = 'Table View Cell Scroll Count Indicator' # This description is used to generate tags and improve search results. diff --git a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift index 9c6501a..e7b7922 100644 --- a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift +++ b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift @@ -11,6 +11,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate private var dynamicUnpagedHeight:Bool = false var y:CGFloat = -1000 private var topConstraint : NSLayoutConstraint! + var rectHeight:CGFloat? public var opacity:CGFloat = 1 { didSet { @@ -31,6 +32,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate public init(tableView:UITableView) { self.tableView = tableView tableView.layoutIfNeeded() + self.rectHeight = self.tableView.frame.height super.init() scrollCountView.translatesAutoresizingMaskIntoConstraints = false tableView.addSubview(scrollCountView) @@ -48,6 +50,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate rightConstraint = NSLayoutConstraint(item: scrollCountView, attribute: .Trailing, relatedBy: .Equal, toItem: tableView, attribute: .Leading, multiplier: 1, constant: tableView.contentSize.width) tableView.addConstraint(rightConstraint) showCellScrollCount(false) + } public func showCellScrollCount(animated:Bool) { @@ -69,17 +72,26 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate func updateScrollPosition() { - //var currentCellRect:CGRect? + var percentage: CGFloat? + if let h = self.rectHeight { + percentage = (self.tableView.contentOffset.y)/(self.tableView.contentSize.height - h) + if (percentage < 0) { + percentage = 0 + } + + if let index = self.tableView.indexPathForRowAtPoint(CGPoint(x: 0, y: percentage!*self.tableView.contentSize.height)) { + scrollCountView.currentScrollCountNum = index.row + } + } + let indexPaths = tableView.indexPathsForVisibleRows var currentCellRect:CGRect? if let indexPaths = indexPaths { if indexPaths.count > 0 { currentCellRect = tableView.rectForRowAtIndexPath(indexPaths[0]) - scrollCountView.currentScrollCountNum = indexPaths[0].row } } - guard let currentCellRectu = currentCellRect else { return } @@ -116,24 +128,16 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate return } - let oneDistance = tableView.bounds.size.height / CGFloat(totalScrollCountNum) - let currentCellHeight = currentCellRectu.size.height - let currentCellOffset = currentCellRectu.origin.y - let currentOffset = tableView.contentOffset.y - - let dxp = (currentOffset - currentCellOffset)/currentCellHeight - let dx = dxp * oneDistance - - var finalY = tableView.contentOffset.y + ((tableView.bounds.size.height*CGFloat(scrollCountView.currentScrollCountNum)) / CGFloat(totalScrollCountNum)) + dx - - if (finalY < 0) { - finalY = 0 - } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { - finalY = tableView.contentSize.height - scrollCountViewHeight + if let p = percentage { + var finalY = tableView.contentSize.height * percentage! + + if (finalY < 0) { + finalY = 0 + } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { + finalY = tableView.contentSize.height - scrollCountViewHeight + } + topConstraint.constant = finalY } - - topConstraint.constant = finalY } } - } From 4c0484ed497e44b96bd53daaa9f9f8074cf0b4b9 Mon Sep 17 00:00:00 2001 From: Nejc Date: Tue, 15 Nov 2016 09:46:35 +0100 Subject: [PATCH 4/7] podspec idiot fix --- MRTableViewCellCountScrollIndicator.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MRTableViewCellCountScrollIndicator.podspec b/MRTableViewCellCountScrollIndicator.podspec index a272fef..cfe0395 100644 --- a/MRTableViewCellCountScrollIndicator.podspec +++ b/MRTableViewCellCountScrollIndicator.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'MRTableViewCellCountScrollIndicator' - s.version = '0.0.7 + s.version = '0.0.7' s.summary = 'Table View Cell Scroll Count Indicator' # This description is used to generate tags and improve search results. From fd410599f2a3521efbd656ff3ca03ea866a50e20 Mon Sep 17 00:00:00 2001 From: Nejc Date: Fri, 18 Nov 2016 13:26:42 +0100 Subject: [PATCH 5/7] now with new actually working ability --- .../MRTableViewCellCountScrollIndicator.swift | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift index e7b7922..5503e82 100644 --- a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift +++ b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift @@ -10,8 +10,8 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate private var dragging:Bool = false private var dynamicUnpagedHeight:Bool = false var y:CGFloat = -1000 - private var topConstraint : NSLayoutConstraint! - var rectHeight:CGFloat? + private var topConstraint: NSLayoutConstraint! + var rectHeight:CGFloat = 0 public var opacity:CGFloat = 1 { didSet { @@ -32,7 +32,7 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate public init(tableView:UITableView) { self.tableView = tableView tableView.layoutIfNeeded() - self.rectHeight = self.tableView.frame.height + super.init() scrollCountView.translatesAutoresizingMaskIntoConstraints = false tableView.addSubview(scrollCountView) @@ -49,8 +49,8 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate rightConstraint = NSLayoutConstraint(item: scrollCountView, attribute: .Trailing, relatedBy: .Equal, toItem: tableView, attribute: .Leading, multiplier: 1, constant: tableView.contentSize.width) tableView.addConstraint(rightConstraint) + self.rectHeight = self.tableView.frame.height showCellScrollCount(false) - } public func showCellScrollCount(animated:Bool) { @@ -71,24 +71,20 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate } func updateScrollPosition() { - - var percentage: CGFloat? - if let h = self.rectHeight { - percentage = (self.tableView.contentOffset.y)/(self.tableView.contentSize.height - h) + if totalScrollCountNum == 0 { + return + } + self.rectHeight = tableView.bounds.size.height + var currentCellRect:CGRect? + var percentage: CGFloat = 0 + if (self.rectHeight != 0) { + percentage = (self.tableView.contentOffset.y)/(self.tableView.contentSize.height - self.rectHeight) if (percentage < 0) { percentage = 0 } - - if let index = self.tableView.indexPathForRowAtPoint(CGPoint(x: 0, y: percentage!*self.tableView.contentSize.height)) { + if let index = self.tableView.indexPathForRowAtPoint(CGPoint(x: 0, y: self.tableView.contentOffset.y + percentage*self.rectHeight)) { scrollCountView.currentScrollCountNum = index.row - } - } - - let indexPaths = tableView.indexPathsForVisibleRows - var currentCellRect:CGRect? - if let indexPaths = indexPaths { - if indexPaths.count > 0 { - currentCellRect = tableView.rectForRowAtIndexPath(indexPaths[0]) + currentCellRect = tableView.rectForRowAtIndexPath(index) } } @@ -97,7 +93,6 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate } if (dynamicUnpagedHeight) { - let viewSize = tableView.bounds.size.height let tableContentHeight = tableView.contentSize.height let scrollLimit = tableContentHeight - viewSize @@ -124,20 +119,24 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate size: CGSize(width: width, height: scrollCountViewHeight) ) } else { - if totalScrollCountNum == 0 { - return - } + let oneDistance = tableView.bounds.size.height / CGFloat(totalScrollCountNum) + let currentCellHeight = currentCellRectu.size.height + let currentCellOffset = currentCellRectu.origin.y + var currentOffset = tableView.contentOffset.y + percentage*self.rectHeight + let dxp = (currentOffset - currentCellOffset)/currentCellHeight + + let dx = dxp * oneDistance + var ratio = CGFloat(scrollCountView.currentScrollCountNum) / CGFloat(totalScrollCountNum) + var finalY = tableView.contentOffset.y + dx + ratio*scrollCountViewHeight + ratio*self.rectHeight - if let p = percentage { - var finalY = tableView.contentSize.height * percentage! - - if (finalY < 0) { - finalY = 0 - } else if(finalY > tableView.contentSize.height - scrollCountViewHeight) { - finalY = tableView.contentSize.height - scrollCountViewHeight - } - topConstraint.constant = finalY + if (finalY < 0) { + finalY = 0 + } else if(finalY > (tableView.contentOffset.y + self.rectHeight - scrollCountViewHeight)) { + var difY = finalY - (tableView.contentOffset.y + self.rectHeight - scrollCountViewHeight) + print(difY) + finalY -= difY } + topConstraint.constant = finalY } } } From cd50420bf90cd625878e4c1675d66c64dc39c676 Mon Sep 17 00:00:00 2001 From: Nejc Date: Fri, 18 Nov 2016 13:28:46 +0100 Subject: [PATCH 6/7] print cleanup --- .../Classes/MRTableViewCellCountScrollIndicator.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift index 5503e82..461553c 100644 --- a/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift +++ b/MRTableViewCellCountScrollIndicator/Classes/MRTableViewCellCountScrollIndicator.swift @@ -133,7 +133,6 @@ public class MRTableViewCellCountScrollIndicator:NSObject, UIScrollViewDelegate finalY = 0 } else if(finalY > (tableView.contentOffset.y + self.rectHeight - scrollCountViewHeight)) { var difY = finalY - (tableView.contentOffset.y + self.rectHeight - scrollCountViewHeight) - print(difY) finalY -= difY } topConstraint.constant = finalY From a6e8a4ba414fc1471c78fe44763561306dae6f35 Mon Sep 17 00:00:00 2001 From: Nejc Date: Mon, 21 Nov 2016 10:48:01 +0100 Subject: [PATCH 7/7] 0.0.8 bump --- MRTableViewCellCountScrollIndicator.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MRTableViewCellCountScrollIndicator.podspec b/MRTableViewCellCountScrollIndicator.podspec index cfe0395..1bafb6a 100644 --- a/MRTableViewCellCountScrollIndicator.podspec +++ b/MRTableViewCellCountScrollIndicator.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'MRTableViewCellCountScrollIndicator' - s.version = '0.0.7' + s.version = '0.0.8' s.summary = 'Table View Cell Scroll Count Indicator' # This description is used to generate tags and improve search results.