I have multiple view controllers set up with push segues, they are all a grey colour with 50% opacity. The problem is when pushing to next VC they overlap and it doesn't look great at all.
I have been looking online and only answer I could find was to remove the animation. I do not want to do this as I have set up tap gesture swipes and the UI do not look that pleasing if there isn't the push animation!
Please see video example of it in action here -
http://tinypic.com/player.php?v=2ez6x7a%3E&s=9#.Vnh6SJOLSX0
Solution I:
If you are ok to remove the animation, Set animated false on UINavigationController.pushViewController in Swift
self.navigationController!.pushViewController(viewController, animated: false)
Solution II:
If you don't, then you may need to hide the current ViewController before you push the new viewcontroller as follows:
yourCurrentViewController.view.hidden = YES;
Related
I have experienced a strange thing when I use UINavigationController with push method. Let's say we have a ViewController with two buttons (sign in & sign up). When user taps each of the buttons, the app presents the proper ViewController, but the UI elements, placed on that ViewController (for example UITextFields, Buttons) appearing first, while the transition animation still taking place.
I use a function to setup my layout in each ViewController and I'm not dealing with Storyboard.
I tried to use viewWillLayoutSubviews(), viewWillAppear(), etc, but experienced the same thing...
How can I reach smooth transition between the views?
Finally I solved it. The overlapping Viewcontroller did not have background color defined.
I have a problem in that in swift when i set the UINavigationController to hidden using
navController.navigationBarHidden = true
it also stops the swipe back ability on any viewcontrollers that are pushed onto the stack. there doesn't seem to be any accepted fix, and i've tried setting the interactivePopGestureRecogniser as suggested by others, but this doesn't work any more either (i think that may have worked in swift 1?)
pls halp.
You can add your own interactive gesture and animation (called an interactive custom transition animation). It can be just like the default swipe gesture, or you can use use a different gesture and a different animation.
I've been toying around with an idea of a UINavigationController that has an image as background and every view controller on the stack would have transparent background so the background image of the UINavigationController is visible across all of them.
I tried implementing this the most obvious way (have root view controller with fullscreen image and view controllers with transparent background, but this results in awkward issues with animation).
Digging around I found HotelTonight app managed to implement this. See a recording of their user interface. I made: https://www.youtube.com/watch?v=qvynwhCj5oM&list=UUKnxsyMsRRRJs_Yw9GZVOFw
Does anybody have some suggestion on a right path implementing this?
It's probably better to subclass UIViewController to have a particular setup for its background and navigation controller style. For example, in the viewDidLoad method of your UIViewController subclass, set its background to a certain image. You can also use this to style your navigation bar (certain colors for the barButtonItems, etc). Then each new view controller you create is a subclass of your skinned view controller.
If your background is an image, you will still get the weird animation effects when a new view controller slides in over the top of the old one; the background will slide in as well. Depending on how custom you want to make your transition animations, there are things you can do to play around with the views during the transition. UIPresentationController might present some solutions for making a more custom animated transition.
Edit: To emulate the Hotel now app, I made a UINavigationController with an image as a background, and controllers on top with clear backgrounds. On a push, I animate the alpha of the first controller to 0 while the segue is happening. On returning, I set the alpha back to 1.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.view.alpha = 1;
}
-(void)didClickButton:(id)sender {
[UIView animateWithDuration:.25 animations:^{
self.view.alpha = 0;
}];
// the transition itself is a push segue defined in the storyboard
}
I believe that the Hotel App's background works well with this method since it's very dark. Not sure if it would be very effective for brighter apps or apps with a lot of content in the controller being covered.
I have what I thought would be a pretty easy thing to accomplish. Basically I have one view controller with some data, let's call it view controller A. When you click a button, I want a second view controller (B) to show up overlaying the first one. However, I don't want B to fully cover A. I want B to be smaller and to basically create a dark transparent background through which you can still see A.
I've tried this through storyboard a lot where I create a segue of type modal and then I played with the presentation options (form, sheet, etc...), but basically always what happens is that the B view controller simply flows up and covers all of A.
There are some guides to doing this in ios 7 and Objective-C, but I haven't been able to manage to translate those to Swift/ios 8 yet (also this is for iPhone).
I'm not sure if anyone has tried this yet in ios 8, but if someone could give me some hints as to how to accomplish this, that would be awesome.
Thanks!
Try the following in prepareForSegue -
toBePresentedVC.view.backgroundColor = UIColor.clearColor()
presentingViewController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
presentingViewController.presentViewController(self, animated: true completion: nil)
You can try few alpha options with background color to get a transparent effect with some color.
Ok this is a little hard to explain but here I go. On "View1" I use a UIView animation to go to "View2". The animation I do is a fade through black, switching views. I get to View2 by doing -addSubview. Now lets say we are on View2, and my action gets called to go to View3 using presentModalView. Since I need to remove the "View2" view, I do [self.view removeFromSuperview]; in my viewDidDisappear method so that the animation going to View3 is not screwed up.
Here is the problem, when I go from my "View3" back to "View1" I use a presentModalView again with an animation flip. Now you know when you usually flip views, you see a background in the back of a color (usually white), instead it is my "View2". So it is like it is being cached in a way.
Does anyone know why this is? If I need to post code, I can.
You can actually check this tutorial about using the UINavigationController:
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
To hide your Navigation Bar you can actually see this post:
Is it possible use UINavigationController but hide its navigation bar (replace it with customized toolbar) and go back button
Edit 1:
Uploaded the project now here: http://www.2shared.com/file/qU-QT8fl/Project.html
Read the ReadMe.text file. :P