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.
Related
So I am working on an app and am finally getting to a point where I am starting to build actual modules instead of playgrounds and utility apps for tests. So I really want to do this right since I am jumping into the real deal right now. I was hoping to get advice that will help me accomplish my goals for the apps "flow" without me hacking something together that will come back to bite me later.
So imagine I have a home screen(a single view controller) that can branch to multiple storyboards. The mechanism I want to trigger transitions is the user grabbing an image on the home screen with their finger, and flicking it off the screen. When the image is no longer on screen, I'd like to transition to a storyboard that corresponds to that image. For instance, the user might flick the "settings" image to open a settings panel.
[home storyboard] -- [user flicks image off screen] --> [alternate storyboard]
I have already accomplished this kind of, but with the way I am doing it now I am unsure how to be able to navigate back from the second storyboard back to the home storyboard. It also seems unclean and hacky to me.
Right now it is set up as such:
Home is its own storyboard - main.storyboard
Home contains one simple viewcontroller
Alt is another storyboard - alt.storyboard
Alt contains a navigationcontroller
How can I facilitate things such that Alt's navigation controller will recognize that it was just in the Home storyboard, so that it will provide a "back" button for navigating back home?
Or, if anyone has any advice as to how I might accomplish this in a neater way, I would greatly appreciate it. I want each "module" (ie alt.storyboard's contents) to be in different storyboards for organizational sake.
Here is the code I use to seque to my second storyboard:
if !(recognizer.view!.window == nil) {
print("object left window")
let viewController: UIViewController = (self.storyboard?.instantiateViewControllerWithIdentifier("Alt"))! as UIViewController
self.presentViewController(viewController, animated: true, completion: nil)
}
Thanks so much for taking the time to check this out, let me know if I have not been clear enough.
you could put the main viewcontroller (from Home storyboard) itself into a navigation controller and simply push the initial viewcontroller from the storyboard you want to reach (in your example Alt storyboard) with a custom transition. so the viewcontrollers from all the other storyboards except of Home should not be embedded in a navigation controller!
I'm working on replacing UINavigationControllers and other iOS standard UI classes with https://github.com/CosmicMind/Material and am stuck with NavigationBarViewController in particular. I know that under the hood it uses parent/child controller setup to present new view controllers on itself but I can't figure out how can I have just basic navigation VC push onto the stack with a back button on the left to go back. Going through the source code of NavigationBarViewController doesn't seem like there is a way to do it. Is it possible to do it with NavigationBarViewController?
To transition the mainViewController, which is the body of the NavigationBarViewController, you can use the
transitionFromMainViewController
method. It supports animation options, though, not the MoveIn or Push animation.
In order to do that, you need to use the transition method that is available in the MaterialAnimation API.
Example:
let vc: HashtagListViewController = HashtagListViewController()
vc.view.layer.addAnimation(MaterialAnimation.transition(.MoveIn, direction: .Right), forKey: kCATransitionFromRight)
navigationBarViewController?.transitionFromMainViewController(vc)
Basically what you are doing is tapping into the transition animation for the UIViewController.view.layer.
If you do not want to go to that effort, the
transitionFromMainViewController
offers some nice out of the box animations that you can use.
In a future version of Material, there will be an entire NavigationViewController Stack that will do all that you are asking.
Update
In Material 1.36.0, there are two new classes, NavigationBar and NavigationController. NavigationController is a subclass of UINavigationController, so all the features for pushing and popping UIViewControllers on the stack of items is the same, while getting the ability to customize the controller's look and feel with ease.
The example App project shows how to use this.
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;
I modified AAPLSearchBarEmbeddedInNavigationBarViewController in Apple's UICatalog sample code so that it pushes another instance of AAPLSearchBarEmbeddedInNavigationBarViewController onto the navigation stack when a cell is selected. In the second view controller the UISearchBar set as the title view of the UINavigationBar (just like the first one) isn't tappable (unlike the first the one). This seems like a bug. How do I fix it? Here is my modified UICatalog code:
https://github.com/stevemoser/UICatalog
Also I tested with with Xcode 6 and 7. It's broken in both.
The solution is to set the first VC self.definesPresentationContext = NO when navigating away from it and making sure to call self.definesPresentationContext=YES in the view did appear so that the visible VC allows defines the presentation context.
Thanks goes to Rory McKinnel who put me on the right track.
I created a storyboard for my app which contains the following:
Initial view controller on my storyboard is a Tab Bar Controller (let's call it myTabCtrlr)
myTabCtrlr has forward segues pointing to several other controllers:
a. First segue points to a custom UIViewController (let's call it vc1) on which I create an interactive UIView (let's call it popview1) which is initially hidden. There's a button (let's call it showPopView1) on vc1's view which when clicked would show popview1
b. Second segue points to a navigation controller, which embeds a view controller with 3 buttons, each pointing to an (end) controller.
c. Third segue points to another navigation controller with a similar setup as (b)
On several of these (end) controllers, there's a button similar to vc1's showPopView1 that when tapped, I'd like to switch back to vc1 and programmatically bring up popview1, which I'm doing as follows (but it's not working):
myTabCtrlr.selectedIndex = 0;
//I get a handle to vc1 then
vc1.popview1.hidden = NO;
When I do that, it goes back to the first tab and shows vc1 view (which is good) but it does not show popview1. I tried many different ways to do it but no luck.
Note that if I'm actually on vc1 and I tap the showPopView1 button, then popview1 comes up normally.
Does anybody know why that is the case? This only started after I transitioned to using storyboard. thanks.
After spending hours looking at various ways to solve this problem, and focusing on reverse segues and similar methods, I was able to solve it using a totally different method.. I wanted to share this with others so nobody has to waste so much of their time (although I noticed slow response to my post. Maybe I didn't make the subject attractive enough :)..
It's a really simple solution, but quite effective. I used a Singleton pattern object. When coming from the rest of the tabs, I set a flag in the singleton that vc1 checks in its viewWillAppear method, shows popview1, and immediately resets the flag.. works like a charm!