How to Uninstall a UIView programmatically - autolayout

In Interface builder the power of size classes lets you install constraints or uninstall them. In code you can do something similar by toggling the active property.
Interface Builder also lets you install or uninstall views. However, I would like to be able to do this programatically. UIView doesn't appear to have an active property. Is there any way I can uninstall a view programmatically? I'm looking for something where I can simply toggle a boolean property and the view and its constraints go into a dormant state and the view is no longer visible ands its constraints are no longer constraining until it is toggled to be non-dormant and then the view and the constraints work again.
Is this possible? Any workarounds?

A view's hidden property does not equate to the view being installed or not. From the Apple documentation on Installing and Uninstalling Views for a Size Class:
A runtime object for an uninstalled view is still created. However,
the view and any related constraints are not added to the view
hierarchy and the view has a superview property of nil. This is
different from being hidden. A hidden view is in the view hierarchy
along as are any related constraints.
So it sounds like the equivalent in code is something like:
// "Uninstall" the view from the superview
[self.myView removeFromSuperView];
// And add it back in
[self.view addSubview:self.myView]
You'd still have the view in memory, though not hidden. However you go about this I'm guessing your activating and deactivating constraints as this view comes and goes (unless the view itself is overlaying other things on the screen and not requiring a rearrangement of objects).

Related

Daydream keyboard implementation

I am attempting to implement the Daydream keyboard into an app built in Unity and am not able to get this to work. I have added the keyboard prefab as a sibling of the main camera and added two input fields with the onpointerclick function added as instructed. I however get a null reference exception and assume this is due to the daydream keyboard delegate field being blank. The example scene in the SDK shows the daydream delegate example prefab but I am unsure how to implement this for two input fields. Also does the keyboard render in the Unity editor or must it be built and run on a phone?
This is an old question and has probably already been answered, but I figured I'd publicize my answer anyway.
For those reading, if you haven't checked out the Keyboard Demo scene that can be found within the Demos folder of the Google VR Unity package, I would highly recommend doing so. Following this object hierarchy has worked for me in the past.
To answer your first question, it seems that they have included a KeyboardDelegateExample object within the scene's hierarchy, and then used this object as the Keyboard Delegate in the GVRKeyboardManager.
They manage to fake an Input Field by creating a background and overlaying a Text object on top. If this method does not suffice and using an Input Field is crucial in your particular case, then drop your Input Fields into two separate GVRKeyboardCanvas objects.
Clicking on either canvas will activate the GVR Keyboard. You may have to add a small script to manage the transitioning of the input field.
Lastly, no the GVR Keyboard does not render in the Unity Editor, it only appears while running a build. Hopefully this will be addressed in later releases. There are also Keyboard plugins that you may find useful on the Asset Store.

In JavaFX, how to make a whole tree of nodes read-only?

In JavaFX, I'd like to provide a read-only view with full support for navigation and copying to the clipboard.
I need the capability to scroll a ScrollPane and to switch tabs on a TabPane. I need the capability to make selections so the user can copy. Because disabling the controls undermines these capabilities, disabling the controls will not work for me.
It would be nice if the implementer of the view didn't have to know about this read-only business and I could impose this read-only state upon the view from the outside, by recursively visiting all of its nodes.
TextInputControl.editable seems to do exactly what I need.
However, ComboBoxBase.editable only prevents the user from typing into the control, not changing the selected value. (But, there is this: How to make checkbox or combobox readonly in JavaFX, which works for all descendants ofButtonBase too.)

JavaFX nodes - How to make them resizable by the end user?

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.
Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.
The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.
However, I have failed to find out how I can make these nodes resizable by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter what the OS.
Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)
Many thanks,
Ian.
As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.
The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.
I found something that you can use : Dragging to resize a JavaFX Region
This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :
Only height resizing is currently implemented.
This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8
Hope this helps.

Android - NestedFragments participate in populating the options menu

i am implementing the new nested fragment feature and had stumble into a problem.
my view is basically this:
a main activity(A) that includes a fragment(B), this fragment(B) includes a pager adapter that has 3 pages each of them is a fragment(C) also.
previously to the new getchildfragmentmanger this was not doable, but it works perfectly.
but one issue did arise, i want fragments C to be able to participate in populating the option menu.
i tired putting setHasOptionsMenu(true) in the onActivityCreated method on each of my C fragments and overriding also onCreateOptionsMenu but nothing happens...
if i try to populate the menu from fragment B (which is the container of the pager adapter) i can change the menu items...
any thoughts ?
Thanks.
Yes they can.
With android 4.2 or support library revisiion 11 nested fragments participate in populating options menu, as allways you need to call setHasOptionsMenu(true) during onCreate().
But if you are using ActionBarSherlock they won't, you have to manually call from parent fragment onCreateOptionsMenu() nested fragment method onCreateOptionsMenu().
Update: issue
From my read of the source code, it appears that the implementations of FragmentManager and Activity only work with the root FragmentManager for adding to the options menu/action bar, not and child FragmentManager instances.
Fragment B presumably will need to manage the options menu/action bar on behalf of the contents of the ViewPager, changing what is in the options menu/action bar based upon the pages being shown and hidden in the pager.

Autorotate with a UINavigationController

I am a little unclear on how to rotate views that are sitting on a UINavigationController.
I have overridden the UINavigationController object with one of my own that overrides:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { return YES; }
I have one view on the stack on the controller and that view is loaded from a xib with two views in it. I want to switch from portrait to landscape. Normally I would handle this by changing the view from within the nib files of the view itself. Do I have to implement the rotational code within the Navigation Controller or just within my view code?
(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
That willAnimate code is what I'm used to using in the view itself, but I'm still not seeing the view being changed, and I'm thinking it may be that I need to access the view in the NavigationController and change that, or even override the same method in the Navigation Controller and do my view switching there.
Any suggestions? I've never actually done this before and just found out the TabViewControllers and NavigationControllers are both portrait mode only by default.
Turns out it wasn't possible to change the view because I was trying to changes the RootView on the Navigation Controller. I got around this by placing my own pseudo root view controller that never gets seen in the root spot on the Navigation stack. I overrode a few of the navigation controls to account for this so the functionality would continue the same and I'd be able to change my desired perceived root view as I needed to.
A start in the right direction can be found in this link:
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller’s-root-view-controller/

Resources