Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation #402

Open
MaksGre opened this issue Nov 5, 2020 · 4 comments
Open

Animation #402

MaksGre opened this issue Nov 5, 2020 · 4 comments
Labels

Comments

@MaksGre
Copy link

MaksGre commented Nov 5, 2020

Describe the question
When the user swipes drawerViewController I fire my animation to move the custom tabbar, the problem is that my animation somehow gets executed with the drawerViewController swipe animation settings. I checked everything several times. I started my animation without a swipe and then the animation happens correctly, with my settings. If I swipe drawerViewController, then my animation happens with the drawerViewController settings, which are specified in line 510 of PulleyViewController. How can this be explained and circumvented?

Code snippets and helpful information
https://yadi.sk/i/U_D2H6Vdd1WyFQ

Pulley Information (optional):

  • Any customizations or tweaks: Yes
  • Did you Subclass: Yes

Xcode Information (optional):

  • Version: 11.6
  • Installation: Cocoapods
  • Interface Builder: No
@ulmentflam
Copy link
Contributor

The PulleyViewController implements the UIScrollViewDelegate that will call the setDrawerPosition function to be called on particular interactions. Is it possible you are calling that animation in the drawerPositionDidChange delegate method or another delegate method?

@MaksGre
Copy link
Author

MaksGre commented Nov 21, 2020

Yes, I am starting my animation from drawerPositionDidChange method.

@ulmentflam
Copy link
Contributor

ulmentflam commented Nov 23, 2020

@MaksGre Can you describe where you are calling those animations relative to the pulley delegate methods?

@MaksGre
Copy link
Author

MaksGre commented Nov 24, 2020

final class BankBuilder {
        static func build() -> BankViewController {
		let mainContentVC = UIStoryboard.bank.instantiateViewController(AccountViewController.self)
		let drawerContentVC = UIStoryboard.bank.instantiateViewController(OperationsViewController.self)
		let viewController = BankViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
...
                 return viewController
        }
}

final class BankViewController: PulleyViewController {
	var tabBar: TabBarController? {
		tabBarController as? TabBarController
	}
...
	override func drawerPositionDidChange(drawer: PulleyViewController, bottomSafeArea: CGFloat) {
		guard pulleyPosition != drawer.drawerPosition else { return }
		pulleyPosition = drawer.drawerPosition

		switch drawer.drawerPosition {
		case .collapsed:
			interactor?.request(.didCollapseTable)
			tabBar?.didScrollUp()
		case .partiallyRevealed:
			interactor?.request(.didExpandTable)
			tabBar?.didScrollDown()
		default: return
		}
	}
}

final class TabBarController: UITabBarController {
...
	func didScrollDown() {
		lowerTabBar()
	}
...
	private func lowerTabBar() {
		guard customTabBar.frame.origin.y == tabBarOriginMinY else { return }
		var frame = customTabBar.frame
		frame.origin.y = tabBarOriginMaxY
		animate {
			self.customTabBar.frame = frame
		}
	}
...
	private func animate(block: @escaping () -> Void) {
		UIView.animate(
			withDuration: Appearance.animationDuration,
			delay: Appearance.animationDelay,
			usingSpringWithDamping: Appearance.springWithDamping,
			initialSpringVelocity: Appearance.initialSpringVelocity,
			options: Appearance.animationOptions,
			animations: {
				block()
		})
	}
...
}

private struct Appearance {
	static let animationDuration: TimeInterval = 1
	static let animationDelay: TimeInterval = 0
	static let springWithDamping: CGFloat = 0.7
	static let initialSpringVelocity: CGFloat = 1
	static let animationOptions: UIView.AnimationOptions = [.curveEaseInOut]
}

in didScrollUp method about the same code and the same effect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants