No Clear example regarding transition of two UIViews in same ViewController
Hey thanks for your awesome work and fulfilling the gap found in Hero transition, which is transitioning between UIViews but i couldn't found any example how i could transition two UIViews in same ViewController , will be much appreciated if you could add example or share an idea whatever possible earliest . Thanks in advance.
That's a great question, I should really add one. I'm a bit busy now, but may be able to add one in the next couple days. But to help you get started it should look something like this:
let animator = Animator(
fromView: fromView,
toView: toView,
container: self.view,
isPresenting: isPresenting
)
view.addSubview(toView)
toView.frame = ...
animator.animate { complete in
toView.view.alpha = 1
fromView.view.alpha = 0
}
If that doesn't work let me know. I have to go away from the computer now or else I would try it out myself.
Also checkout the transition animator here as an example for what a normal view controller transition is doing
push view animate not work with this pod .. only works with files in example
@fifisamy make sure you enable shift on the navigationController not the actual view controller. If that doesn't work feel free to open another issue
Hi, so I have a very specific case which I am wondering if this library can handle. let's say I have 2 uiviews viewA & viewB. I have some sub uiviews inside both viewA and viewB. let's say they are subviewA and subviewB. now i want to animate the transition from subviewA to subviewB while hiding viewA and showing viewB. is it possible to do so and if so then a code snippet will be much appreciated.
@nafis042 yes it can, is this during a UIViewController transition?
@wickwirew unfortunately no. it is just 2 uiviews inside same viewcontroller. maybe I can explain my issue in a little bit of detail. I have a container view inside my view controller. then I have 2 uiviewcontrollers which are kept as uiviews. now the container view can show one uiview at a time and hide another. so when some action occurs I am showing one uiview and hide other.
@nafis042 yea then the code should look something like the example above. Keep in mind though the Animator will only manage hiding the views while the animation is going on.
Take a look at the modal transition for a UIViewController transition. You can see it inserts the new view controller into the view hierarchy. Then when the animation is finished it sets the alpha of the other view to 0 to make sure its hidden. You could also remove the old view completely from the view hierarchy as well, and add it back if you need to switch back. Hope this helps!
Hi, do you plan to add animation between two UIViews in same VC? @wickwirew
Yes like telegram profile photo transition affect
On Wed, Apr 5, 2023 at 3:52 AM BayramInanc @.***> wrote:
Hi, do you plan to add animation between two UIViews in same VC?
— Reply to this email directly, view it on GitHub https://github.com/wickwirew/Shift/issues/1#issuecomment-1496696993, or unsubscribe https://github.com/notifications/unsubscribe-auth/APZH7FQQZPCGCKCVIYOI6MTW7SQZZANCNFSM4UC675FA . You are receiving this because you authored the thread.Message ID: @.***>
-- Best Regards,
Shozab Haider
+92 312 4434 759
@BayramInanc this should already be possible. See the example https://github.com/wickwirew/Shift/issues/1#issuecomment-733978975. If that doesnt work or you need further help let me know
Ok thanks for getting back to me. I will check
On Wed, Apr 5, 2023 at 3:56 AM Wes Wickwire @.***> wrote:
@BayramInanc https://github.com/BayramInanc this should already be possible. See the example #1 (comment) https://github.com/wickwirew/Shift/issues/1#issuecomment-733978975. If that doesnt work or you need further help let me know
— Reply to this email directly, view it on GitHub https://github.com/wickwirew/Shift/issues/1#issuecomment-1496699928, or unsubscribe https://github.com/notifications/unsubscribe-auth/APZH7FTJWYAH4F5HMWSXLH3W7SRIXANCNFSM4UC675FA . You are receiving this because you authored the thread.Message ID: @.***>
-- Best Regards,
Shozab Haider
+92 312 4434 759
Yea happy to help! I can always try to put together an example if need be
Hi ,
`import UIKit
import Shift
class ViewController: UIViewController {
@IBOutlet weak var fromView: UIButton!
@IBOutlet weak var toView: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
shift.enabled = true
toView.alpha = 0
}
override func viewDidAppear(_ animated: Bool) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2){
self.doit()
}
}
func doit(){
let animator = Animator(
fromView: fromView,
toView: toView,
container: self.view,
isPresenting: true
)
animator.animate {[self] complete in
fromView.alpha = 0
toView.alpha = 1
}
}
}`
I added like this but nothing happened. I have two button one in bottom left, other is in top right. No animation happened @wickwirew
@BayramInanc When I had tried this locally I assumed that the view's would be added and removed as they are needed. In your case the views are always in the view, with an alpha of 0 to hide them. When the Animator tries to get snapshots of views since they already exist with an alpha of 0 they are not visible. Try adding and removing the views as needed. It would be nice if it worked the way you have it setup, but there isnt a great way. Since the Animator cannot assume you don't want the 0 alpha.
Here is an example:
import UIKit
import Shift
class ViewController: UIViewController {
let fromView: UIView = {
let view = UIView()
view.backgroundColor = .systemBlue
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let toView: UIView = {
let view = UIView()
view.backgroundColor = .systemBlue
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(fromView)
NSLayoutConstraint.activate([
fromView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 60),
fromView.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -60),
fromView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 60),
fromView.heightAnchor.constraint(equalToConstant: 100),
])
toView.shift.id = "view"
fromView.shift.id = "view"
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.view.addSubview(self.toView)
NSLayoutConstraint.activate([
self.toView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor, constant: 60),
self.toView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor, constant: -60),
self.toView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: -60),
self.toView.heightAnchor.constraint(equalToConstant: 100),
])
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
let animator = Animator(
fromView: self.fromView,
toView: self.toView,
container: self.view,
isPresenting: true
)
animator.animate { complete in
self.fromView.removeFromSuperview()
}
}
}
}
@BayramInanc When I had tried this locally I assumed that the view's would be added and removed as they are needed. In your case the views are always in the view, with an alpha of
0to hide them. When theAnimatortries to get snapshots of views since they already exist with an alpha of0they are not visible. Try adding and removing the views as needed. It would be nice if it worked the way you have it setup, but there isnt a great way. Since theAnimatorcannot assume you don't want the0alpha.Here is an example:
import UIKit import Shift class ViewController: UIViewController { let fromView: UIView = { let view = UIView() view.backgroundColor = .systemBlue view.translatesAutoresizingMaskIntoConstraints = false return view }() let toView: UIView = { let view = UIView() view.backgroundColor = .systemBlue view.translatesAutoresizingMaskIntoConstraints = false return view }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(fromView) NSLayoutConstraint.activate([ fromView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 60), fromView.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -60), fromView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 60), fromView.heightAnchor.constraint(equalToConstant: 100), ]) toView.shift.id = "view" fromView.shift.id = "view" } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.view.addSubview(self.toView) NSLayoutConstraint.activate([ self.toView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor, constant: 60), self.toView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor, constant: -60), self.toView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: -60), self.toView.heightAnchor.constraint(equalToConstant: 100), ]) self.view.setNeedsLayout() self.view.layoutIfNeeded() let animator = Animator( fromView: self.fromView, toView: self.toView, container: self.view, isPresenting: true ) animator.animate { complete in self.fromView.removeFromSuperview() } } } }
Thank you for your effort. I am using the library. You have made a great job. It's such a fantastic library. Btw, in future for my project, I will add interactive animation feature. İs it possible right?
@BayramInanc thank you! As it stands there is no interactive support, I've always wanted to add it but have never gotten around to it unfortunately