ios - Making beautiful transitions at PageViewController -
i want make custom transition in pageviewcontroller: while user moves next slide (scroll) background image dissolves image.
such effect have apple weather (except there background video).
what i've done:
- i've made uiviewcontoller background image (that image need change).
- i've placed containerview in uiviewcontroller, containerview have embed pageviewcontroller. uiviewcontroller -> containerview -> pageviewcontroller
at point i'm stuck, have working pageviewcontroller shared background image (from top uiviewcontroller), have no idea go next.
now can catch page changing delegate (main viewcontoller):
func pagechanged(currentpage: int) {}
and default delegate method (pageviewcontoller) (i have 2 slides, don't know how better):
func pageviewcontroller(pageviewcontroller: uipageviewcontroller, didfinishanimating finished: bool, previousviewcontrollers: [anyobject], transitioncompleted completed: bool) { let prevcontroller = previousviewcontrollers [contentviewcontroller] if completed { if prevcontroller[0].index == 0 { delegate.pagechanged(1) } else { delegate.pagechanged(2) } } }
but instant function, can't here animation in dependency of user swipes :).
i totally agree vasily. need use uicollectionview
, use self.collectionview.pagingenabled = yes;
. can control scrollview contentoffset via uiscrollviewdelegate
.
optional func scrollviewdidscroll(_ scrollview: uiscrollview)
the code:
func scrollviewdidscroll(scrollview: uiscrollview) { var currentx = scrollview.contentoffset.x var ratio = currentx / uiscreen.mainscreen().bounds.size.width var previouspageindex = floor(ratio) var nextpageindex = ceil(ratio) ratio = ratio - previouspageindex }
for instance, if ratio
0.33, transition 33% between page previouspageindex
, page nextpageindex
. can use values set alpha values in uiimageview
s:
func scrollviewdidscroll(scrollview: uiscrollview) { var currentx = scrollview.contentoffset.x var ratio = currentx / uiscreen.mainscreen().bounds.size.width var previouspageindex = floor(ratio) var nextpageindex = ceil(ratio) ratio = ratio - previouspageindex fromimageview.alpha = 1.0 - ratio; toimageview.alpha = ratio; }
the pageviewcontroller
doesn't allow control scrolling itself. transition discrete event here. swipe gesture discrete event , can add smooth effect it. pan gesture can code more complex , dirty.
Comments
Post a Comment