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.
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)
Bringing UIViews to front on tap
It won't work like in the link.
1, You need to setup the tap gesture recogniser
2, You need to create an @objc function and call this on action.
//paste it into viewDidLoad.
let tap = UITapGestureRecognizer(target: self, action: #selector(tapped))
tap.cancelsTouchesInView = false
//Uncomment next line, if you want more than one tap to activate gesture.
//tap.numberOfTapsRequired = 5
self.view.addGestureRecognizer(tap)
// Create a function
@objc func tapped(){
self.view.bringSubviewToFront(UIViewWhatYouWantToBringToFront)
}
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
Saving Audio After Effect in iOS
Dismiss Keyboard with Swipe Gesture
Programmatically Set Uipageviewcontroller Transition Style to Scroll
Xcode6/Swift: Unrecognized Selector Sent to Instance
Errortype' Is Not Convertible to 'Nserror'
Setting Custom Http Headers in Alamofire in iOS 7 Not Working
Cannot Invoke Initializer for Type Unsafemutablepointer<Uint8>
Import Xctest into a Dynamic Framework
Most Efficient/Realtime Way to Get Pixel Values from iOS Camera Feed in Swift
Why am I Getting an Error Regarding Bolts Framework and Facebooksdk When I'm Not Even Using Bolts
How Is It I Can Animate the Change in Bar Tint Color of a Uinavigationbar But Not a Uitabbar
How to Crop a 4*3 Image in Photolibrary or Camera in Swift
Changing the Shape of a Uiview Border
How to Create a Rounded Rectangle Label in Xcode 7 and Swift 2
When Should I Use Anyobject Insted of Uibutton in Swift