Skip to content

Commit

Permalink
added support of landscape orientation and transition
Browse files Browse the repository at this point in the history
  • Loading branch information
askopin committed Feb 11, 2019
1 parent 3f20fb2 commit 2699be3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
13 changes: 1 addition & 12 deletions liquid-swipe.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,9 @@

Pod::Spec.new do |s|
s.name = 'liquid-swipe'
s.version = '0.7.0'
s.version = '0.8.0'
s.summary = 'An page conroller with liquid animation'
s.swift_version = '4.2'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

# s.description = <<-DESC
#TODO: Add long description of the pod here.
# DESC

s.homepage = 'https://github.com/Cuberto/liquid-swipe'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
71 changes: 69 additions & 2 deletions liquid-swipe/Classes/LiquidSwipeContainerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ open class LiquidSwipeContainerController: UIViewController {
private var maxVertRadius: CGFloat {
return view.bounds.height * 0.9
}
private var initialSideWidth: CGFloat = 15.0
private var initialSideWidth: CGFloat {
if #available(iOS 11.0, *) {
return 15.0 + view.safeAreaInsets.right
}
return 15.0
}
private var initialWaveCenter: CGFloat {
return view.bounds.height * 0.7167487685
}
Expand Down Expand Up @@ -206,6 +211,10 @@ open class LiquidSwipeContainerController: UIViewController {
self.delegate?.liquidSwipeContainer(self, didFinishTransitionTo: viewController, transitionCompleted: false)
}
}
if let mask = nextViewController?.view?.layer.mask as? WaveLayer {
mask.frame = self.view.bounds
mask.updatePath()
}
currentPage?.pop_add(animation, forKey: "animation")
}
}
Expand Down Expand Up @@ -282,9 +291,14 @@ open class LiquidSwipeContainerController: UIViewController {
}
if self.shouldCancel,
let viewController = self.previousViewController {
viewController.view.isHidden = true
self.delegate?.liquidSwipeContainer(self, didFinishTransitionTo: viewController, transitionCompleted: false)
}
}
if let mask = previousViewController?.view?.layer.mask as? WaveLayer {
mask.frame = self.view.bounds
mask.updatePath()
}
previousViewController?.view.pop_add(previousViewAnimation, forKey: "animation")
guard nextViewController != nil else {
return
Expand Down Expand Up @@ -496,6 +510,10 @@ open class LiquidSwipeContainerController: UIViewController {
guard let page = nextVC.view else {
return
}
if let mask = page.layer.mask as? WaveLayer {
mask.frame = view.bounds
mask.updatePath()
}
if let currentPage = currentPage {
view.insertSubview(page, belowSubview: currentPage)
} else {
Expand All @@ -519,6 +537,10 @@ open class LiquidSwipeContainerController: UIViewController {
guard let page = previousVC.view else {
return
}
if let mask = page.layer.mask as? WaveLayer {
mask.frame = view.bounds
mask.updatePath()
}
if let currentPage = currentPage {
view.insertSubview(page, aboveSubview: currentPage)
} else {
Expand All @@ -529,7 +551,7 @@ open class LiquidSwipeContainerController: UIViewController {
}

private func apply(mask: WaveLayer, on view: UIView) {
mask.frame = view.bounds
mask.frame = self.view.bounds
mask.updatePath()
view.layer.mask = mask
}
Expand Down Expand Up @@ -560,6 +582,51 @@ open class LiquidSwipeContainerController: UIViewController {
}
currentPage?.pop_add(animation, forKey: "animation")
}

override open func viewSafeAreaInsetsDidChange() {
if let mask = self.currentPage?.layer.mask as? WaveLayer {
if mask.sideWidth > 0 {
mask.sideWidth = initialSideWidth
mask.updatePath()
csBtnNextLeading?.constant = -(mask.waveHorRadius + mask.sideWidth - 8.0)
view.layoutIfNeeded()
}
}

}

override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
let btnNextWasHidden = btnNext.isHidden
btnNext.isHidden = true
currentPage?.layer.mask = nil
previousViewController?.view?.layer.mask = nil
nextViewController?.view?.layer.mask = nil

coordinator.animate(alongsideTransition: { (_) in
}) { (_) in
if let currentPage = self.currentPage {
let hasNextPage = self.nextViewController != nil
let maskLayer = WaveLayer(waveCenterY: self.initialWaveCenter,
waveHorRadius: hasNextPage ? self.initialHorRadius : 0,
waveVertRadius: self.initialVertRadius, sideWidth: hasNextPage ?self.initialSideWidth : 0)
self.apply(mask: maskLayer, on: currentPage)
}
if let nextPage = self.nextViewController?.view {
let maskLayer = WaveLayer(waveCenterY: self.initialWaveCenter, waveHorRadius: 0, waveVertRadius: self.initialVertRadius, sideWidth: 0)
self.apply(mask: maskLayer, on: nextPage)
}
if let prevPage = self.previousViewController?.view {
let maskLayer = WaveLayer(waveCenterY: self.initialWaveCenter, waveHorRadius: 0, waveVertRadius: self.initialVertRadius, sideWidth: prevPage.bounds.height)
self.apply(mask: maskLayer, on: prevPage)
}
self.csBtnNextCenterY?.constant = self.initialWaveCenter
self.csBtnNextLeading?.constant = -(self.initialHorRadius + self.initialSideWidth - 8.0)
self.btnNext.isHidden = btnNextWasHidden
self.btnNext.transform = CGAffineTransform.identity
self.view.layoutIfNeeded()
}
super.viewWillTransition(to: size, with: coordinator)
}
}

//MARK: Animation helpers
Expand Down
16 changes: 16 additions & 0 deletions liquid-swipe/Classes/WaveLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ internal class WaveLayer: CAShapeLayer {
var waveHorRadius: CGFloat
var waveVertRadius: CGFloat
var sideWidth: CGFloat

override public init(layer: Any) {
if let waveLayer = layer as? WaveLayer {
waveCenterY = waveLayer.waveCenterY
waveHorRadius = waveLayer.waveHorRadius
waveVertRadius = waveLayer.waveVertRadius
sideWidth = waveLayer.sideWidth
} else {
waveCenterY = 0
waveHorRadius = 0
waveVertRadius = 0
sideWidth = 0
}
super.init(layer: layer)
}

init(waveCenterY: CGFloat, waveHorRadius: CGFloat, waveVertRadius: CGFloat, sideWidth: CGFloat) {
self.waveCenterY = waveCenterY
self.waveHorRadius = waveHorRadius
Expand Down

0 comments on commit 2699be3

Please sign in to comment.