ParallaxScrollable
public protocol ParallaxScrollable: UIScrollViewDelegate
Protocol extending UIScrollViewDelegate
to adjust the scrolling of a given view to mimic a parallax motion between the two views.
Default implementations are given for parallaxScrollViewDidScroll(_:)
on all adopters, and for configureParallaxScrollInset(_:)
for UIViewController
s.
-
The reference view that the
UIScrollView
will scroll over, whose position is adjusted on scrolling theUIScrollView
.Declaration
Swift
var parallaxHeaderView: UIView! { get }
-
The
UIScrollView
whose offset drives the parallax motion of theheaderView
.Declaration
Swift
var parallaxScrollView: UIScrollView! { get set }
-
The mask applied to the
parallaxHeaderView
that provides clipping ofparallaxHeaderView
if the content of aparallaxScrollView
is short enough for theparallaxHeaderView
to be visible underneath the scrollable content.Declaration
Swift
var parallaxHeaderMask: CAShapeLayer { get }
-
The parallax motion of the
headerView
is implemented by setting theconstant
property of this constraint.Declaration
Swift
var parallaxHeaderViewTopConstraint : NSLayoutConstraint! { get set }
-
configureParallaxScrollInset(_:)
Default implementationShould set the
contentInset
of theparallaxScrollView
to allow theheaderView
to be seen above the content ofparallaxScrollView
.Default Implementation
Default implementation of
configureParallaxScrollInset(_:)
forUIViewController
s.Sets the content inset of
parallaxScrollView
to allow theheaderView
to be fully visible above the content of theparallaxScrollView
. The bottom inset of theparallaxScrollView
is adjusted to allow the content to be visible above thebottomLayoutGuide
. This will typically by called fromviewDidLayoutSubviews()
, to reset thecontentInset
as the size of other content changes.headerOverlap()
andbottomOverlap()
are used to calculate the necessary values.Declaration
Swift
func configureParallaxScrollInset(minimumHeight:CGFloat)
-
parallaxScrollViewDidScroll(_:scrollRate:bouncesHeader:maskingHeader:)
Default implementationShould update
headerViewTopConstraint.constant
to mimic a parallax motion. With the given parameter. A default implementation is given.Default Implementation
Default implementation for parallax scrolling a header view. Typically this will be called from
scrollViewDidScroll:
.Declaration
Swift
func parallaxScrollViewDidScroll(scrollView:UIScrollView, scrollRate:CGFloat, bouncesHeader:Bool, maskingHeader:Bool)
-
parallaxHeaderOverlap()
Extension methodDeclaration
Swift
public func parallaxHeaderOverlap() -> CGRect
Return Value
The intersection of
headerView
andparallaxScrollView
in the frame ofparallaxScrollView.superview
. -
parallaxBottomOverlap()
Extension methodDeclaration
Swift
public func parallaxBottomOverlap() -> CGRect
Return Value
The intersection of
the bottomLayoutGuide
andparallaxScrollView
in the frame ofparallaxScrollView.superview
.
-
updateParallaxHeaderMask()
Extension methodUpdates
parallaxHeaderMask
to clip theparallaxHeaderView
, preventing it being seen beneath short content.Declaration
Swift
public func updateParallaxHeaderMask()