How to Bring a View in Front of Another View, in Swift

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



Leave a reply



Submit