Skip to content
This repository was archived by the owner on Jun 17, 2018. It is now read-only.

Commit cdbe03b

Browse files
committed
not call UIView.animate if no animation
According to UIView's document, completion block in UIView.animate is performed at the beginning of the next run loop cycle. This will cause an obvious pause when switching to a view controller not next to the current one.
1 parent bb73e87 commit cdbe03b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Pod/Classes/PagingMenuController.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,22 @@ open class PagingMenuController: UIViewController {
175175
pagingViewController.currentViewController = nextPagingViewController
176176

177177
let duration = animated ? options.animationDuration : 0
178-
UIView.animate(withDuration: duration, animations: {
179-
() -> Void in
178+
let animationClosure = {
180179
pagingViewController.positionMenuController()
181-
}) { [weak self] (_) -> Void in
182-
pagingViewController.relayoutPagingViewControllers()
183-
184-
// show paging views
185-
self?.showPagingMenuControllers()
186-
187-
self?.onMove?(.didMoveController(to: nextPagingViewController, from: previousPagingViewController))
180+
}
181+
let completionClosure = { [weak self] (_: Bool) -> Void in
182+
pagingViewController.relayoutPagingViewControllers()
183+
184+
// show paging views
185+
self?.showPagingMenuControllers()
186+
187+
self?.onMove?(.didMoveController(to: nextPagingViewController, from: previousPagingViewController))
188+
}
189+
if duration > 0 {
190+
UIView.animate(withDuration: duration, animations: animationClosure, completion: completionClosure)
191+
} else {
192+
animationClosure()
193+
completionClosure(true)
188194
}
189195
}
190196

0 commit comments

Comments
 (0)