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 a7311c1 commit 9b2c629
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Sources/Cacao/UIScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,23 @@ open class UIScrollView: UIView {

let scrollerBounds = UIEdgeInsetsInsetRect(bounds, contentInset)

if (contentSize.width - contentOffset.x) < scrollerBounds.size.width {
contentOffset.x = (contentSize.width - scrollerBounds.size.width)
// dont allow content offset lower than end of content
let contentOffsetMin = CGPoint(x: scrollerBounds.size.width - contentSize.width,
y: scrollerBounds.size.height - contentSize.height)

if contentOffset.x < contentOffsetMin.x {
contentOffset.x = contentOffsetMin.x
}
if (contentSize.height - contentOffset.y) < scrollerBounds.size.height {
contentOffset.y = (contentSize.height - scrollerBounds.size.height)

if contentOffset.y < contentOffsetMin.y {
contentOffset.y = contentOffsetMin.y
}

// non-bouncing content offset should always be zero or or smaller
contentOffset.x = min(contentOffset.x, 0)
contentOffset.y = min(contentOffset.y, 0)

// no scrolling if content size is smaller or exactly the size of the scroll view
if contentSize.width <= scrollerBounds.size.width {
contentOffset.x = 0
}
Expand Down

0 comments on commit 9b2c629

Please sign in to comment.