Xcode which view is active
How would you handle that? This is probably obvious to everyone, but for me the code had to be self. Be careful in generalizing this solution to other situations. For example, if you're using a UIPageViewController, views for UIViewControllers who are not the current page may still have a non-nil window property because they are being rendered off-screen. Moshe in that case, use topViewController.
Please note that this answer doesn't say anything about the real visibility. For example, if the app is in background above IF statement will say YES while view is not really visible. Show 6 more comments. If you are using, for example, a UISplitViewController , the master view will always return true for if viewController. Is this still true in xCode 7. I may be doing something wrong, but I am pretty sure this is the case. For those of you looking for a Swift 2. Alex Stanciu 5, 2 2 gold badges 22 22 silver badges 31 31 bronze badges.
Benjamin Benjamin 7, 3 3 gold badges 32 32 silver badges 45 45 bronze badges. Not sure why but I found that doing self. Once removed, it works fine. When I added this to viewWillAppear self. Nice post! This doesn't work if the view controller is contained inside a navigation controller and that controller is added to the tab bar controller.
The call to selectedViewController will return the navigation controller and not the current view controller. Or even use 'self. I made a swift extension based on progrmr's answer. Besi Besi Chris Prince Chris Prince 6, 1 1 gold badge 43 43 silver badges 58 58 bronze badges. XCode 6. The one that has worked for me is the following Hope this helps someone. EI Captain v2. MrTristan MrTristan 5 5 silver badges 16 16 bronze badges.
I have found this way to be more reliable than the accepted answer, when a navigation controller is available. All views accessed in nav will show full screen, even though XCode shows them offset to the bottom. A minor IB bug probably. Search by keywords or tags Submit Search Clear search query Additional information about Search by keywords or tags Supported Searches:.
Xcode 11 View Controllers no longer aligned. Click again to start watching. Asked by uncletr. Copy to clipboard Share this post. Copied to Clipboard. Add a Comment. Accepted Answer. I can confirm the same problem after upgrade. Hope it is a bug that is corrected quickly. Plain lines straight lines with no end-caps. Plain lines show where edges align. For example, Interface Builder uses simple lines when aligning the leading edge of two or more views. These lines can also be used to connect items that have a 0-point space between them.
Solid Lines. Dashed Lines. Red Lines. One of the items affected by this constraint has an error. Either the item has an ambiguous layout, or its layout is not satisfiable. Orange Lines. Orange lines indicate that the frame of one of the items affected by this constraint is not in the correct position based on the current set of constraints.
Interface Builder also shows the calculated position for the frame as a dashed outline. Blue Lines. Equal Badges. Interface Builder shows constraints that give two items an equal width or an equal height as a separate bar for each item. Greater-than-or-equal and less-than-or-equal badges. Interface Builder lists all the constraints in the document outline, grouping them under the view that holds them. Constraints are held by the closest view that contains both items in the constraint.
The constraints are listed using pseudocode. These listings are often long, and they frequently start with a similar set of views, so you may have to increase the width of the outline before you can see meaningful information. Selecting a constraint in the outline highlights that constraint in the canvas.
Use this feature to help you quickly identify the constraint you want to examine. However, as the layout becomes more complex, it quickly becomes hard to find specific constraints. You are often better off examining the constraints one view at a time—either by selecting the view in the canvas or by examining the view in the Size inspector. The Size inspector lists all the constraints affecting the currently selected view.
Required constraints appear with a solid outline, and optional constraints appear with a dashed outline. The description lists important information about the constraint. It always includes the affected attribute and the other item in the constraint. It may also include the relationship, the constant value, and the multiplier or ratio.
The diagram at the top of the above screenshot shows which attributes are affected by constraints. The list then shows only those constraints affecting the selected attributes.
This includes all the values from the constraint equation: the first item, the relation, the second item, the constant, and the multiplier. You can also mark the constraint as a placeholder. These constraints exist only at design time. They are not included in the layout when the app runs. You typically add placeholder constraints when you plan to dynamically add constraints at runtime.
By temporarily adding the constraints needed to create a nonambiguous, satisfiable layout, you clear out any warnings or errors in Interface Builder. For the first and second item, however, your options are more limited. You can swap the first and second item inverting the multiplier and constant, as needed. If you need to move the constraint to a completely different item, delete the constraint and replace it with a new constraint.
Some editing is also possible directly from the Size inspector. To make additional changes, double-click the constraint to select it and open it in the Attribute inspector. However, if you need a different size at design time, you can set a placeholder intrinsic content size. This placeholder affects the size of the view only in Interface Builder. It does not have any effect on the view at runtime. The top and bottom layout guides represent the upper and lower edge of the visible content area for the currently active view controller.
The layout guides adopt the UILayoutSupport protocol, giving the guide a length property, which measures the distance between the guide and the respective edge of the view. These guides can also act as items in a constraint, supporting the top, bottom, and height attributes. The guides also provide topAnchor , bottomAnchor , and heightAnchor properties, to simplify the programmatic creation of constraints.
Just click on the disclosure triangle. Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews.
The default margins are 8 points on each side. In UIKit, the NSLayoutAttribute enumeration defines a number of attributes to represent top, bottom, leading, trailing, left, and right margins.
0コメント