SwiftUI iOS15 新API大全之SwiftUI swi

2022-02-18  本文已影响0人  iCloudEnd

在 iOS 15 中,SwiftUI 添加了一个新的swipeActions修饰符。它允许您将自定义滑动操作添加到列表中的一行。

func swipeActions<T>(edge: HorizontalEdge = .trailing, allowsFullSwipe: Bool= true, content: () -> T) -> some View where T : View

我们可以使用此方法将滑动操作添加到充当列表中的一行的视图中。指出HorizontalEdge滑动动作的来源,即.leading或.trailingButton并用实例定义我们的个人动作。

实战代码

import Foundation

struct Session: Identifiable {
  let id = UUID()
  let title: String
}

class WWDCViewModel: ObservableObject {
  @Published private(set) var sessions: [Session] = []
  
  init() {
    self.sessions = getSessions()
  }
  
  private func getSessions() -> [Session] {
    return [
      Session(title: "AR Quick Look, meet Object Capture"),
      Session(title: "ARC in Swift: Basics and beyond"),
      Session(title: "Accelerate networking with HTTP/3 and QUIC"),
      Session(title: "Accessibility by design: An Apple Watch for everyone"),
      Session(title: "Add intelligence to your widgets"),
      Session(title: "Add rich graphics to your SwiftUI app"),
      Session(title: "Add support for Matter in your smart home app"),
      Session(title: "Adopt Quick Note"),
      Session(title: "Analyze HTTP traffic in Instruments"),
      Session(title: "Apple’s privacy pillars in focus")
    ]
  }
}

让我们构建一个列表视图来填充WWDC21 会议视频。

image.png
上一篇 下一篇

猜你喜欢

热点阅读