当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。