當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Swift Never zIndex(_:)用法及代碼示例

實例方法

zIndex(_:)

控製重疊視圖的顯示順序。

聲明

func zIndex(_ value: Double) -> some View

參數

value

此視圖的相對 front-to-back 排序;默認值為 0

詳述

當您想要控製視圖的front-to-back 順序時,請使用zIndex(_:)

在此示例中,有兩個重疊的旋轉矩形。最前麵由較大的索引值表示。


VStack {
    Rectangle()
        .fill(Color.yellow)
        .frame(width: 100, height: 100, alignment: .center)
        .zIndex(1) // Top layer.


    Rectangle()
        .fill(Color.red)
        .frame(width: 100, height: 100, alignment: .center)
        .rotationEffect(.degrees(45))
        // Here a zIndex of 0 is the default making
        // this the bottom layer.
}

可用版本

iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+

相關用法


注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never zIndex(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。