cosmicmind / motion Goto Github PK
View Code? Open in Web Editor NEWA library used to create beautiful animations and transitions for iOS.
Home Page: http://cosmicmind.com
License: MIT License
A library used to create beautiful animations and transitions for iOS.
Home Page: http://cosmicmind.com
License: MIT License
Getting a huge flickering
I'm currently trying to transition from one VC1 to VC2 when a user clicks a cell. The transitions and their have been set to be the boxView cell of a collection view within VC1 to the background view of VC2. When I transition over to VC2 and back half of VC2 is missing from the transition. There's also an issue when I dismiss VC2 the boxView of VC1 collection view cell is 1/4 the size that it should be and shifted along the X axis.
VC1 didSelectCell code:
`if let cell = collectionView.cellForItem(at: indexPath) as? CourseCell {
let cardData = "cell-\(indexPath.row)"
cell.boxView.transition([.useNoSnapshot, .spring(stiffness: 250, damping: 25)])
cell.boxView.motionIdentifier = cardData
let vc = CourseViewController(nibName: CourseViewController.identifier, bundle: nil)
vc.course = courses[indexPath.row]
vc.isMotionEnabled = true
vc.motionTransitionType = .none
vc.view.motionIdentifier = cardData
vc.view.transition([.source(cardData), .useNoSnapshot, .spring(stiffness: 250, damping: 25)])
vc.lessonsTableView.motionIdentifier = "course-\(indexPath.row)"
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseIn, animations: {
cell.boxView.transform = CGAffineTransform.init(scaleX: 0.95, y: 0.95)
}) { _ in
self.present(vc, animated: true)
cell.boxView.transform = .identity
}
}`
VC1 cellForRowAt code:
`cell.motionIdentifier = "cell-\(indexPath.row)"
cell.boxView.motionIdentifier = "course-\(indexPath.row)"
cell.transition([.fadeIn, .scale(1)])`
I've spent the passed couple of days trying to solve this and no luck.
I want to install the framework using the pod. Is there any possibility to install this framework like pod
Thank you
I notice that a lot of the APIs are the same, with some minor changes. Is this a fork of https://github.com/HeroTransitions/Hero ?
I want to push/pop a view controller with just a fade-in fade-out transition between them. I couldn't achieved it, instead I see the screen is flashing white in the middle of the transition. Please check out the GIF provided below for clarification.
Is there a way to have just a fade transition when pushing/popping view controllers?
Can I create custom transition? Here is my interaction.
VC_1 (fromView)
- topViewA
- contentViewA
- buttonA
- bottomViewA
VC_2 (toView)
- buttonB
- topViewB
- contentViewB
bottomViewA
of VC_1 and topViewB
of VC_2 is same view.
When VC_1 present VC_2, VC_1 and VC_2 is overwrapped with bottomViewA and then VC_1 is translated by y. It looks like scrolling effects.
So view layer looks like during transition
- topViewA
- contentViewA
- buttonA
- buttonB
- bottomViewA = topViewB
- contentViewB
Here is my code
toViewSnapshot.frame = CGRect(x: 0, y: bottomViewA.y, width: width, height: height)
fromViewSnapshot.addSubview(toViewSnapshot)
UIView.animate(withDuration: 10, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
snapshotFromView.frame = CGRect(x: 0, y: -bottomViewA.y, width: toView.frame.width, height: toView.frame.height)
}, completion: { _ in
self.snapshotViews.values.forEach { $0.removeFromSuperview() }
self.snapshotViews.removeAll()
transitionContext.completeTransition(true)
})
If I added fromViewSnapshot and toViewSnapshot to containerView, I cannot create view hierarchy that I want (animating views are added toViewSnapshot or fromViewSnapshot)
After some search for a good solution, I found your project. This is awesome!
Could you give some advise if I use Motion
?
Motion looks like an awesome library! Playing around with it now, and noticed something.
When adding the pod the delegates of UIImagePickerControllerDelegate
is not called:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any])
and
func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
When removing Motion from the Podfile, the delegates work.
I got this message when presenting this Navigationcontroller.
"Unbalanced calls to begin/end appearance"
(The animation works as expected)
class AnimatableNavController: UINavigationController {
var transtype:MotionTransitionAnimationType?
open override func viewDidLoad() {
super.viewDidLoad()
isMotionEnabled = true
motionTransitionType = transtype ?? .push(direction: .right)
motionNavigationTransitionType = transtype ?? .push(direction: .right)
}
}
The development branch seems to be updated to swift 4.2 but .podspec
file should also have swift_version = '4.2'
Current .podspec:
Lines 2 to 4 in 0132613
Hello. I'm using Motion to achieve a rotation effect on a button. This is what I'm doing :
if isAdding {
// Close adding, resetting all stuff
btnAdd?.animate(MotionAnimation.rotate(45))
isAdding = false
} else {
// Open adding
btnAdd?.animate(MotionAnimation.rotate(-45))
isAdding = true
}
When I need to rotate back the button, I'm not able to achieve the "back" animation. How can I do? It seems the button starts always from the original position.
Hello! How can I control an interactive transition? In Hero we can do this like:
`
@objc func pan(gr: UIPanGestureRecognizer) {
let translation = gr.translation(in: self)
switch gr.state {
case .began:
parentViewController?.dismiss(animated: true, completion: nil)
case .changed:
Hero.shared.update(translation.y / bounds.height)
default:
let velocity = gr.velocity(in: self)
if ((translation.y + velocity.y) / bounds.height) > 0.5 {
Hero.shared.finish()
} else {
Hero.shared.cancel()
}
}
}
`
But in Motion we have the following lines, that commented:
`
/**
Motion.shared
func update(progress: Double)
func end()
func cancel()
func apply(transitions: [MotionTargetState], to view: UIView)
*/
`
May be there is another way to do this?
I use both Material and Motion in my project. I'm wondering if there's a way to animate depth change?
If not, would you add it in the future?
Thanks in advance
Would be nice if we can use a custom timing function by passing the control points that define the animation curve.
this would be part of the identity of cosmic mind
Hi,
The issue is that if there is a motion transition happening and the user closed the app, the application stuck when open it again and can't do anything with it.
Im using a TabBarController with fadeIn and fadeOut transition modes.
My issue is that some subviews of one of the presenting view controllers are setting the alpha back to 1 after I animated them with fadeOut before exiting the view controller.
It sounds like a problem with the fade transitions used between view controllers and views being animated as well.
Update: Problem persist after removing the subview fade animation. Seems to be completely related to the transition mode.
Using version 1.1.2 of cocoapods.
Pods/Motion/Sources/Preprocessors/MotionPreprocessor.swift:33:5
'weak' should not be applied to a property declaration in a protocol and will be disallowed in future versions
weak var motion: MotionTransition! { get set }
As of 1.3.2 viewWillAppear(_:)
, viewWillDisappear(_:)
, viewDidAppear(_:)
, and viewDidDisappear(_:)
are not invoked when we make transitions through MotionTransition
since you removed calls to beginAppearanceTransition(_:animated:)
and endAppearanceTransition()
in commit 6b95e48
Material's TabsController
is a victim of this change. I am not getting viewWillAppear(_:)
-s anymore which my child view controllers heavily rely on
I have a background view with the following applied to it inside the home controller:
bkgd.isMotionEnabled = true bkgd.motionIdentifier = "bkgd" bkgd.transition([.spring(stiffness: 300, damping: 25), .duration(0.3), .beginWith(modifiers:[.zPosition(0)]), .useGlobalCoordinateSpace])
And inside the transition to controller I have:
bkgd.isMotionEnabled = true bkgd.motionIdentifier = "bkgd" bkgd.transition([.spring(stiffness: 300, damping: 25), .duration(0.3), .beginWith(modifiers:[.zPosition(0)]), .useGlobalCoordinateSpace])
The motion transition type is: motionTransitionType = .autoReverse(presenting: .slide(direction: .right))
and I'm using the standard self.present(vc, animated: true)
to initiate the transition.
The problem: When transition the background comes to the front of the view obscuring all other elements until the transition has finished. At this point it returns to it's respective zPosition. I am using xib's instead of storyboards.
Currently trying have a shadow on a UIView within a UITableViewCell and when performing the transition the cell shadow clips until the end animation state. I have all the normal properties set to false (clipsToBounds etc). First approach was to attach the shadow to the UIView layer and that worked until Motion was introduced to the UITableView:
boxView?.layer.shadowColor = Theme.Colors.shadow!.cgColor boxView?.layer.shadowOpacity = 0.8 boxView?.layer.shadowRadius = 20 boxView?.layer.shadowOffset = CGSize(width: 0, height: 5) boxView?.layer.shadowPath = UIBezierPath(roundedRect: boxView.bounds, cornerRadius:20).cgPath
Second approach is what I'm currently trying and that is to attach the shadow to the transition of the cell:
cell.boxView.isMotionEnabled = true cell.boxView.isMotionEnabledForSubviews = true cell.boxView.motionIdentifier = "box-\(indexPath.row)" cell.boxView.transition([ .shadow(offset: CGSize(width: 0, height: 10)), .shadow(radius: 16), .shadow(color: Theme.Colors.green!), .shadow(opacity: 1), .shadow(path: UIBezierPath(roundedRect: cell.boxView.bounds, cornerRadius: 20).cgPath), .masksToBounds(false), .durationMatchLongest, .forceAnimate, .useGlobalCoordinateSpace, .useScaleBasedSizeChange ]) cell.layoutIfNeeded()
Either approach fails to work and results in the cell shadow being clipped until the end of the animation motion provides.
The UITableView has the following MotionIdentifiers attached to it:
basicTableView.transition([.beginWith(modifiers:[.zPosition(5)]), .useGlobalCoordinateSpace, .fade(0.0), .duration(0.25), .spring(stiffness: 300, damping: 25), .translate(x: -300), .masksToBounds(false)])
Thanks
When I use code as following, the rightBarButtonItem becomes unclickable (XCode 9 + ios 10),
But ios 11 is totally OK. When I changed back to normal UINavigationController, everything is OK again. Would you like to check this problem since there are many people who are still using ios 10.
Thanks a lot!
class AppNavigationController: NavigationController {
open override func prepare() {
super.prepare()
isMotionEnabled = true
motionNavigationTransitionType = .autoReverse(presenting: .zoom)
}
}
This should be creative in showing the different animation styles.
I found the following code in Motion+CALayer.swift
@available(iOS 10, *)
extension CALayer: CAAnimationDelegate {}
The problem is now I want to make my own customize CALayer which conforms CAAnimationDelegate. But because of the "extension CALayer: CAAnimationDelegate {}", it seems I can not do it.
Can you help me to work it out? Thank you.
Hello!
How can a view that doesn't have a motionIdentifier
or simply doesn't match any identifier from the previous view controller to be animated at the same time the presentation animation happens?
I tried to add animations to this view using motionAnimations
but they seem that are not executed.
I additionally tried to use view.motion(...)
to animate this view in viewWillAppear
but if I don''t use delay
I cannot see the animations. I achieved what you can see in next gif adding a delay to the animations of this view after view controller is pushed and before it's popped. As you can notice the white view with the game's description appears after the transition has finished.
Example code:
/********* Pushed view controller's code *********/
override func viewDidLoad() {
super.viewDidLoad()
// Set initial state for animatable views
backgroundImage.motion(.duration(0.0), .translateX(-view.frame.width))
tableView.motion(.duration(0.0), .translateY(view.frame.height))
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let duration = 0.3
let delay = 0.3
let timing = MotionAnimation.timingFunction(.easeInEaseOut)
backgroundImage.motion(.delay(delay), .duration(duration), .translateX(0), timing)
tableView.motion(.delay(delay), .duration(duration), .translateY(0), timing)
}
@IBAction func backButtonDidTouch(_ sender: Any) {
let duration = 0.3
let timing = MotionAnimation.timingFunction(.easeInEaseOut)
backgroundImage.motion([.duration(duration), .translateX(-view.frame.width), timing])
tableView.motion([.duration(duration), .translateY(view.frame.height), timing])
DispatchQueue.main.asyncAfter(deadline: .now() + duration) { [unowned self] in
_ = self.navigationController?.popViewController(animated: true)
}
}
I've just updated our code to utilise the new Motion framework instead of the old one built in to Material.
Using the Motion.rotation(angle:) function on a FabButton (as primary button of a Material Menu) works fine in terms of animating the button. However, we're noticing a flash of the initial animation state at the end of the rotation (GIF recording)
menu.views.first?.animate(animation: Motion.rotation(angle: -90))
Any ideas what might cause this?
I expected the transform to be applied when I applied .duration (0.0) in the motion (...) function, but it did not.
The animation application I want is as follows.
Cell.transform = CGAffineTransform (scaleX: 0, y: 0)
Cell.motion ([. Scale (1), .duration (defaultTimeInterval), .timingFunction (.easeOut)])
I applied the first line to cell.motion (.scale (0), .duration (0)), but internally it seems that the default of duration applies.
If .duration (0), can the transform be applied immediately?
I always appreciate quick answers.
Hello!
Brach: Development.
Version: 2.0.0
Issue: I have a UINavigationController with some viewControllers. And I have a PhotoController which will dismiss interactively.
PhotoController has modalPresentationStyle = .custom
.
Simple code for interactive dismiss:
func pan() {
let translation = panGR.translation(in: nil)
let progress = abs(translation.y / 2 / collectionView!.bounds.height)
switch panGR.state {
case .began:
motionDismissViewController()
case .changed:
MotionTransition.shared.update(TimeInterval(progress))
if let cell = collectionView?.visibleCells[0] as? ScrollingImageCell {
let currentPos = CGPoint(x: translation.x + view.center.x, y: translation.y + view.center.y)
MotionTransition.shared.apply(modifiers: [.position(currentPos)], to: cell.imageView)
}
default:
if progress + abs(panGR.velocity(in: nil).y) / collectionView!.bounds.height > 0.3 {
MotionTransition.shared.finish()
} else {
MotionTransition.shared.cancel()
}
}
}
The issue is if MotionTransition.shared.cancel()
is called, then viewWillDisappear
will be called on the previous controller and after that viewWillDisappear and viewWillAppear
won't be called on every controllers in the UINavigationController (which was under PhotoController).
If comment these lines in MotionTransition.swift
:
then all is fine.
Could you please check. Thanks
It seems as though setting the delegate on a BottomNavigationController causes Motion to be disabled while enabling Motion causes delegate methods to not be called.
Material 2.13.5
Motion 1.3.4
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)
})
})
}`
I want to use my own back button when I push an UIViewController by UINavigationController transition. I tried navigationItem.setHidesBackButton(true, animated: true), but it did not work.
Hi,
When making a transition to a detail viewcontroller with motion while calling and switching back to the main viewcontroller the main viewcontroller will jump up and leaves a 20px gap at the bottom. I put up a example project to reproduce it:
Hi, I don't get how to use TransitionAnimations , in the example bellow the gifs I change my VC class to UINavigationController but cant find the variable motionTransitionType (or something like that ) , and in the examples codes you just used default swift UIViewController and cant find such these methods or Variables to set to .zoom or what .. , can you explain how to use these animations ??
First of all, sorry for my bad English.
I'm using Motion
on my project in UINavigationController
, view blinks with black color when pushing/pop view controller repeatedly after 10 times.
First 10 times of translation is OK and no glitches, but it blinks weirdly by repeating popping vieewcontroller a few times after.
Additional: And some subview blinks when pushing view controller after pushing 10 times.
I just enabled isMotionEnabled
property on my UINavController
and UIViewController
.
Here is my view controller code for setup Motion
:
self.isMotionEnabled = true
self.navigationController?.motionNavigationTransitionType = .autoReverse(presenting: .fade)
current.motionIdentifier = "ppj-header-progress"
I tried to remove motionNavigationTransitionType
but same result.
Update: This issuse is caused on iPhone X, iOS 11.1.1
Update 2: My code works perfectly and not happening any issue on iPhone 4s, iOS 9
Update 3: Not happening black blink issue on iPhone 5s, iOS 11 but some subviews translates weirdly (e.g. blinking layer shadows) when pushing/popping view.
I was running into multiple errors like below:
.../Pods/Material/Sources/iOS/Font.swift:97:59: Cannot force unwrap value of non-optional type 'CGFont' .../Pods/Material/Sources/iOS/Material+NSMutableAttributedString.swift:40:39: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/Material+NSMutableAttributedString.swift:50:42: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/Material+NSMutableAttributedString.swift:61:42: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/Material+UIFont.swift:44:18: Type 'String' has no member 'font' .../Pods/Swift.String:231:16: Did you mean 'count'? .../Pods/Material/Sources/iOS/NavigationItem.swift:44:27: Cannot convert value of type 'Button' to specified type 'IconButton' .../Pods/Material/Sources/iOS/SearchBar.swift:112:83: Type 'String' has no member 'foregroundColor' .../Pods/Material/Sources/iOS/SearchBar.swift:122:83: Type 'String' has no member 'foregroundColor' .../Pods/Material/Sources/iOS/TextStorage.swift:108:93: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/TextStorage.swift:129:45: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/TextStorage.swift:141:45: Use of undeclared type 'NSAttributedStringKey' .../Pods/Material/Sources/iOS/TextStorage.swift:152:48: Use of undeclared type 'NSAttributedStringKey'
The resolutions for this is to change the pods setting to use Swift 4.0. You can do this by selecting your Pods project in the project browser in XCode and then select the 'Material' pod/framework from the list of pods/frameworks on the left.
is there a way to animate multiple attributes of multiple uview objects using same motion duration delay etc.??? or in other words equivalent to UIView.animate
or
Motion.animate(duration: 0.3, animations: { view.translate(x: 0, y: 100) view2.rotate(50) })
This should allow for a number of iterations the animations are played.
HI,
I have a strange problem. If I make transition by navigation controller from 1 to 2 view controller and 2nd viewcontroller has a transparent background so it get for some ms black. but it is possible to observe. Do you know how to solve it?
Thanks.
Say I have a UIViewController UV1 which is embedded in an AppNavigationController and Another two UIViewController UV2 and UV3. I want to push UV2 or UV3 from UV1.
class AppNavigationController: NavigationController {
open override func prepare() {
super.prepare()
isMotionEnabled = true
motionNavigationTransitionType = .autoReverse(presenting: .zoom)
}
}
The problem is both transitions for UV2 and UV3 is "zoom".
If I want the transition for UV2 is zoom, but the one for UV3 is "slide", what should I do to achieve it?
Thanks!
Hello!
How can I remove all animations from my view?
I've tried to do
myView.layer.removeAllAnimations()
But seems it doesn't work properly. I've found method removeAllMotionAnimations
in your extension for CALayer, but it is marked as internal.
build error: Material.framework missing
`
import UIKit
import Material
class ConfirmVC: UIViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
isMotionEnabled = true
motionModalTransitionType = .autoReverse(presenting: .zoom)
super.viewDidLoad()
}.....`
motionModalTransitionType this is not found , with importing Material , Motion , or both
When trying to set an identifier in Obj-C the option to set the motionIdentifier does not exist. I have tried with setMotionIdentifier and with self.label.motionIdentifier.
Am I missing something?
When I tried to code like following as the official documents said
animate([.rotate(270), .fadeOut, .scale(0.01), .delay(1)]){ [weak self] in
}
Xcode gave me "Extra argument in call" compile error.
When I removed .delay(1), everything works fine again.
I also found I can not use .duration(1) like that neither.
Update to Swift 4.2.
The conversion with Xcode 10 is automatic, and we'll be very happy.
Thanks!
I am using the motion library very usefully.
However, I would like to have an event to know the end of motion.
We are currently using a function called delayedCall, but it would be nice to know this as an event.
Are you willing to support this?
Thank you for providing a good library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.