I have 2 UIViewControllers. One is the content an the other is a Slide menu.
And I want to move the button from Controller 2 outside its superview like this
Is that possible? Because I tried to set clipToBounds = NO for the superview. The only result I get is this:
Any suggestion?
Several options here. The most obvious is clipToBounds = NO on the Controller 2's view, and any further subview which the button is contained in.
If you do not wish to set it to NO, then the view cannot be part of the clipped view hierarchy. You then have to move it to a shared superview, such as the container controller's view, the window, etc.
Related
I have a pop up view which is loading from a xib file.In that file there are couple of views, labels and buttons. For specific condition i have hide couple of views and buttons and its working but total height of the parent view of those views and buttons is not changing.
I have set the height constraints of the parent view and tried to change the constant but its not updating.
self.translatesAutoresizingMaskIntoConstraints = YES;
I want to resize the parent view after hide the parent view.
Main window
Changed window after constraints
Hiding the view does not remove it from its parents. It just changes its visibility. The view still remains in the hierarchy. To achieve what you want to do the following:
Constraint the view above and view below the view you want to hide with a lower priority.
remove the view(the one you want to hide) from its superview
I hope this helps
I am trying to design two UIViews in storyboard which overlap and are part of same UIviewController. Only one of them is visible at a time so I set alpha to be 0 or 1 in the code depending upon which one I need to show. The problem is I need to layout these views in Storyboard, and the moment I put the second view, the first view in Storyboard does not responds to mouse clicks, even if I set alpha of second view to 0 in the Storyboard. Is there a way to design both the views and modify them anytime at will easily?
You can explore you view controller's view hierarchy (and select any view you want) with the sidebar
If you don't see the sidebar, tap on the button to expand it
I got a Stack View with view: 1,2,3,4 and 5
Looking for a method to bring the Image View4 from view4 in the Stack view, above all the other views. The reason I need this is because I am moving the Image View4 over the Image View3 in view3.
I have tried to move view3 over view4 in the view hierarchy, but that just swaps their places in the Stack View.
From the UIStackView documentation:
The order of [the views in] the subviews array defines the Z-order of the subviews. If the views overlap, subviews with a lower index appear behind subviews with a higher index.
So since all views in the stack view's arrangedSubviews array are also in the stack view's subviews array, you should be able to use the standard UIView APIs to rearrange the views z-order:
bringSubview(toFront:)
sendSubview(toBack:)
exchangeSubview(at:withSubviewAt:)
I don't know whether this is possible to do in Interface Builder or not.
Remove the image from the stack view and add it to the same view that contains the stack view as a subview, using addSubview(_:). That will put it on top of all other views. You could also use insertSubview(_:aboveSubview:) to insert it directly above the stack view.
You'll need to add constraints to the new view so that it is positioned where you want it.
You can have IBOutlet property in UIViewController but in view hierarchy it is placed in UIStackView.
So you should use
stackView.bringSubviewToFront(myView)
rather then
self.view.bringSubviewToFront(myView)
I'm creating an app that has hundreds of view controllers in interface-builder. Each of these view controllers has a button with a code number. When the button is pressed I want the button to expand and show a few lines of text describing the code number. The problem is that the button is placed within a subview that acts as a frame for the button. Therefore, the expanded button size is going to be constrained to that subview and the text will be cutoff. Is there a way for me to programmatically remove the reference to the sub-view? I can do this in interface-builder, but like I said there are hundreds of these view controllers.
Instead I removing it you could expand the subView's and the UIButton's width. That would allow the button to expand as you'd like it to and you would not have to remove the subViews.
From developer reference:
(void)sizeToFit
Call this method when you want to resize the current view so that it
uses the most appropriate amount of space. Specific UIKit views resize
themselves according to their own internal needs. In some cases, if a
view does not have a superview, it may size itself to the screen
bounds. Thus, if you want a given view to size itself to its parent
view, you should add it to the parent view before calling this method.
Is there a case when a view does not have a superview? What are those cases?
a view doesnt have a superview when the view is the rootview meaing that there's no other view behind it (besides the window possibly)
OR when it was never added to a view obviously :D
If it is your View Controller's view, it doesn't have a superview.