How do I get a crossfade transition with resize on macos using storyboard & NSTabViewController? - swift

On a brand new MACOS application project (swift, storyboards), using the latest available version of xCode (8.3) I can't get a crossfade transition with a NSTabViewController that I add to my story board. The window is not resizing as well.
What am I doing wrong ?
I start by adding a new window controller, I remove its content view controller that I replace by a tabviewcontroller.
The tabview controller comes with two tabs wired to two view controllers. I resize one of them to make it bigger and put random buttons on both of them to be able to check wether the full view is visible or not at runtime.
Everything is left with default settings, as well as the "crossfade" transition of the tabviewcontroller.
But when running the application, tabs change abruptly, and the window doesn't resize to display the new tab.
My goal is to build a preference panel on my storyboard ans I just fail on the first steps.

For crossfade animation to work, you need to connect delegate outlet of the tab view to the tab view controller.
It does not seem smooth resize is supported by the standard tab view, though.

Related

How can I transition to a new view controller within the same window? (Swift/Storyboard, macOS)

I am creating a project that requires changing views. However, no matter what segue I choose, the new view opens in a new window when I press the button to open the new view. Is there any way to have the new view replace the old one in the same window, either programmatically or within the Storyboard?
Yes, the term you want to search for is view controller containment.
Here's the basic idea: Apple ships its own "container" view controllers like UINavigationController and UITabController, which manage view controllers for you (i.e. how they are presented, how you transition from one to the next). If those don't work for you, you can build your own (which can themselves be used within those built-in containers btw). Here's some documentation:
https://www.hackingwithswift.com/example-code/uikit/how-to-use-view-controller-containment
https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

How to edit a View hidden behind other Views in Xcode Storyboard?

Is there an easy way in Xcode to edit a view that is hidden behind other views within the Storyboard? I know I can hide the views in front of it and move the view to the front temporarily, but this is difficult to keep doing over and over again. Is there a way to isolate the view somehow in Storyboard so I can edit it on its own?
Select your view controller in storyboard and Open File Inspector
Select Use Auto Layout and Use Trait Variations
Now select the view you want to hide in your storyboard. Open Attributes inspector. Check/uncheck the installed option to show/hide the selected view. You can hide multiple views by changing this property after selecting all the views.
Don't forget to check this option for all the views while running the app. Else it will crash

UITabBarController functionality with UITabBar

I'm making an app with interface builder using storyboarding.
I want to have a tab bar where no item is selected. This can be accomplished by setting
TabBar.SelectedItem = null;
But if you try to do that, you get the following error:
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
So I can't use the standard UITabBarController. I've created a custom UIViewController, and added a UITabBar. Switching between tabs is working fine, and having no selection is also working as it should.
But I have no idea how to show my other view controllers from my custom view controller with the tab bar. Remember that I'm using interfacebuilder, so I can't just create my view controllers in code as new objects and add them to the view. (as suggested in UITabBar funcionality without UITabBarController)
So how do I show my own views without using the UITabBarViewController?
Edit: Still haven't found a solution, but I did a hacky fix. Simple create an other tab bar and place it on top of the original tab bar. Listen to those events and use SelectedIndex to change the view displayed. Then add some function that will select / deselect the items on your own tab bar.
In fact, even if you design your others UIViewControllers from IB, you can instantiate them from code. You'll probably have to play a bit with frame and autoresizing properties to make them fit the part of your main view you want them to display inside, but it's possible.
So, knowing that, a simple solution is to create a simple UIView (we'll call it 'tabFrame') in your main UIViewController, which fill the screen from the top of your UITabBar to the top of the screen; instantiate the UIViewController corresponding to your tabs and add their view as subview of tabFrame. Now you just have to catch item selection from tabbar to hide or show the desired subviews.
Hope I'm clear enough, else don't hesitate to question!
EDIT: pointed out this morning that in storyboarding context, you can effectively instantiate viewControllers / scene from code, but for not loosing designer settings it must NOT be done through directly calling their constructors, but through StoryBoard.InstantiateViewController("vc_identifier") calls, after having set identifiers to VCs in storyboard editor.
See http://docs.xamarin.com/ios/recipes/General/Storyboard/Storyboard_a_TableView for example

Overlay view over tab viewcontrollers

using iphone sdk 4.1. I want to overlay a small view over all my tabcontroller views. this will present itself on the push of a button from one of the tab bar viewcontrollers but then i wish it to remain in place even if the user tabs to another view. How to do?
Thanks
Look at the Apple docs for UITabViewController - you want to add your overlay as a subview of the "view" property on your UITabViewController. This will make it appear above everything on the screen (even over the tab-bar itself, if you're not careful).
You can change the tabs as much as you want - that should just switch the value of the content underneath.

How do you set autosizing to flex in Interface Builder?

I have an iPhone project that I started as a Windows-based app and another View-based app. The Window app has a view which I added and I want to make the view fit within the window. In the View app the view is set to stretch.
Here is what it looks like when it is off.
(source: smallsharptools.com)
And here is when it is on.
http://www.smallsharptools.com/downloads/Stackoverflow/autosizing-on.png
I want to click in the middle of the Autosizing box but it does not do anything. What do I have to do in Interface Builder to make the View in a NIB to flex/stretch the view?
Usually when a view is locked down like that, it means that you have some simulated UI elements in place (like a fake nav bar, tab bar, or status bar). Select the top level view and go to the first tab of the inspector to see if any of those are turned on (you'd also see them on the view of course).
When they are all gone then you can change any of the resizing handles you like.
The view that is provided by default has this kind of limitation but you can overcome this by adding another view (you should delete the first view) to your xib and making this view the view of your file's owner. Besides this you would also have to change the height of this new view to 480 pxls.
Hope this helps.
Thanks,
Madhup