CosmicMind / Motion

A library used to create beautiful animations and transitions for iOS.

Home Page:http://cosmicmind.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slow animations when using present()

TheSwiftyCoder opened this issue · comments

I'm trying to simulate a button down -> button up animation before presenting the view controller and there's a noticeable delay before the present animation is called. I'm using UIView.animate and that is performing the animation smoothly. When it comes to present the controller using there's a delay of a couple of ms before it initiates. I've tried various workarounds to solve this including the code below and it might be related to Motion "Crunching the numbers". Are there any ways to solve this?

                           `DispatchQueue.main.async {
			
			let vc = CourseViewController(nibName: CourseViewController.identifier, bundle: nil)
			vc.course = courses[indexPath.row]
			vc.cellValue = indexPath.row
			vc.view.motionIdentifier = "Course-\(indexPath.row)"
			vc.view.transition([.spring(stiffness: 300, damping: 25), .duration(0.1), .useScaleBasedSizeChange, .forceAnimate, .fadeIn, .corner(radius: 16), .masksToBounds(true)])
			
			self.courseCollection.transition([.beginWith(modifiers:[.zPosition(10)]), .useGlobalCoordinateSpace, .forceAnimate, .fade(0.0), .duration(0.1), .spring(stiffness: 300, damping: 25)])
			
			UIView.animate(withDuration: 0.2, delay: 0.0, options: [.allowUserInteraction, .curveEaseIn], animations: {
				cell.boxView.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
			}, completion: { _ in
				
				UIView.animate(withDuration: 0.3, delay: 0.0, options: [.allowUserInteraction, .curveEaseOut], animations: {
					cell.boxView.transform = CGAffineTransform.identity
					
				}, completion: { _ in
                                              // Slow point here
					self.present(vc, animated: true)
				})
			})
			
		}`  

You have a few things going on, but what sticks out to me is the spring animation. Sometimes it will create what looks like a delay because it needs to smooth out the animation. Also, you are using an async call and then calling UIView animation which forces the main thread to be blocked anyway, as UIView animations stop interactivity. Motion is built using CALayer animations which are non-blocking and allow interaction. Internally as well, the transition animations are non blocking. So I would say not only is the spring an issue, but this is overly complex. Please use Material Gitter to followup. Thank you!