Bring view to front in Swift
You can only modify the zPosition
in the concept of a CALayer
. UIView
does not expose this functionality. It does however expose two methods; sendSubviewToBack:
and bringSubviewToFront:
. This would need to be called on the superview of the view you want to move, and would take the view you want to move as an argument.
Also note that if you simply set userInteractionEnabled = false
on the top view, it will pass touches down to the view below it. This saves messing around with the view's positions.
How to bring a subview to front when selected in Swift?
Use this:
baseView.bringSubview(toFront: imageViewOne)
Swift: Bring View from Stack View to front
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.
Bringing a subview to be in front of all other views
What if the ad provider's view is not added to self.view
but to something like [UIApplication sharedApplication].keyWindow
?
Try something like:
[[UIApplication sharedApplication].keyWindow addSubview:yourSubview]
or
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:yourSubview]
How to bring overlay view to front in swiftUI?
you need to apply your .zIndex(1)
modifier on HStack
containing your DropdownSelector
like this
HStack(){
DropdownSelector(
placeholder: "Day of the week",
options: options,
onOptionSelected: { option in
print(option)
})
.padding(.horizontal)
DropdownSelector(
placeholder: "Day of the week",
options: options,
onOptionSelected: { option in
print(option)
})
.padding(.horizontal)
}
.zIndex(1)
Related Topics
Test Whether a Uiview Is in the Middle of Animation
Gamecenter Authentication in Landscape-Only App Throws Uiapplicationinvalidinterfaceorientation
Swiftui Hide Tabview Bar Inside Navigationlink Views
How to Get a Nsurl from an Xcassets Bundle
Removing Duplicates from Array of Custom Objects Swift
Xcode: "This App Could Not Be Installed at This Time."
Use a Generic Class as a Custom View in Interface Builder
Type 'Any' Has No Subscript Members (Firebase)
How to Disable/Remove Firebaseanalytics
How to Use Core Location/Gps Without Any Internet Connection/Disabled Cellular Network
Button in Uitableviewcell Not Responding Under iOS 7
Changed Project Name in Xcode Causing Naming Error
Wkwebview in Interface Builder
Xcode - Error Creating Lldb Target
Module Compiled with Swift 4.2.1 Cannot Be Imported by the Swift 5.0 Compiler