Skip to content

Commit

Permalink
Working on UIScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Jun 26, 2017
1 parent 9b2c629 commit 6a46cf3
Showing 1 changed file with 0 additions and 106 deletions.
106 changes: 0 additions & 106 deletions Sources/Cacao/UIScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,112 +521,6 @@ open class UIScrollView: UIView {

self.contentOffset = contentOffset
}

private func confined(delta: CGPoint, animated: Bool = false) -> CGPoint {

let bounds = self.bounds

let proposedOffset = CGPoint(x: CGFloat(self.contentOffset.x - delta.x), y: CGFloat(self.contentOffset.y - delta.y))
let visibleBottomCorner = CGPoint(x: CGFloat(self.contentOffset.x + bounds.size.width), y: CGFloat(self.contentOffset.y + bounds.size.height))
let proposedBottomCorner = CGPoint(x: CGFloat(proposedOffset.x + bounds.size.width), y: CGFloat(proposedOffset.y + bounds.size.height))
let contentBounds = CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(self.contentSize.width), height: CGFloat(self.contentSize.height))
if contentBounds.contains(proposedOffset) && contentBounds.contains(proposedBottomCorner) && !self.isPagingEnabled {
return delta
}
var resultOrigin: CGPoint = proposedOffset
let canScrollHorizontal = self.canScrollHorizontal
let canScrollVertical = self.canScrollVertical
if resultOrigin.x < 0 {

if self.bounces && canScrollHorizontal && !animated {
if fabs(resultOrigin.x) < bounds.size.width * UIScrollView.bounceRatio {
resultOrigin.x = self.contentOffset.x - (delta.x * UIScrollView.bounceRatio)
}
else {
resultOrigin.x = -bounds.size.width * UIScrollView.bounceRatio
}
}
else {
resultOrigin.x = 0
}
}
else if resultOrigin.x > 0 && !canScrollHorizontal {
resultOrigin.x = 0
}

if resultOrigin.y < 0 {
if self.bounces && canScrollVertical && !animated {
if fabs(resultOrigin.y) < bounds.size.height * UIScrollView.bounceRatio {
resultOrigin.y = self.contentOffset.y - (delta.y * UIScrollView.bounceRatio)
//resultOrigin.y = resultOrigin.y * UIScrollView.bounceRatio
}
else {
//resultOrigin.y = -bounds.size.height * UIScrollView.bounceRatio
resultOrigin.y = -bounds.size.height * UIScrollView.bounceRatio
}
}
else {
resultOrigin.y = 0
}
}
else if resultOrigin.y > 0 && !canScrollVertical {
resultOrigin.y = 0
}

var resultBottomCorner = proposedBottomCorner

if proposedBottomCorner.x > self.contentSize.width {
if self.bounces && canScrollHorizontal && !animated {
if resultBottomCorner.x - self.contentSize.width < bounds.size.width * UIScrollView.bounceRatio {
resultBottomCorner.x = visibleBottomCorner.x - (delta.x * UIScrollView.bounceRatio)
}
else {
resultBottomCorner.x = self.contentSize.width + bounds.size.width * UIScrollView.bounceRatio
}
}
else {
resultBottomCorner.x = self.contentSize.width
}
resultOrigin = CGPoint(x: CGFloat(resultBottomCorner.x - bounds.size.width), y: CGFloat(resultOrigin.y))
}
if proposedBottomCorner.y > self.contentSize.height {

if self.bounces && canScrollVertical && !animated {
if resultBottomCorner.y - self.contentSize.height < bounds.size.height * UIScrollView.bounceRatio {
resultBottomCorner.y = visibleBottomCorner.y - (delta.y * UIScrollView.bounceRatio)
}
else {
resultBottomCorner.y = self.contentSize.height + bounds.size.height * UIScrollView.bounceRatio
}
}
else {
resultBottomCorner.y = self.contentSize.height
}
resultOrigin = CGPoint(x: CGFloat(resultOrigin.x), y: CGFloat(resultBottomCorner.y - bounds.size.height))
}

if self.isPagingEnabled && animated {
if canScrollHorizontal {
resultOrigin.x = round(resultOrigin.x / bounds.size.width) * bounds.size.width
}
if canScrollVertical {
resultOrigin.y = round(resultOrigin.y / bounds.size.height) * bounds.size.height
}

}

let result = CGPoint(x: CGFloat(self.contentOffset.x - resultOrigin.x), y: CGFloat(self.contentOffset.y - resultOrigin.y))

return result
}

private func scrollContent(_ delta: CGPoint, animated: Bool = false) {

let contentOffset = CGPoint(x: self.contentOffset.x + delta.x,
y: self.contentOffset.y + delta.y)

setContentOffset(contentOffset, animated: animated)
}
}

// MARK: - Supporting Types
Expand Down

0 comments on commit 6a46cf3

Please sign in to comment.