gpt4 book ai didi

ios - 快速呈现 Controller 关闭栏指示器

转载 作者:行者123 更新时间:2023-11-29 05:23:49 25 4
gpt4 key购买 nike

对于你们大多数人来说,这应该是一个简单的问题。现在,像所附照片中那样呈现 View Controller ,其顶部有一个栏(请参见红色箭头),以指示用户可以向下滑动以关闭 Controller 。请帮助解决以下任何问题:

  • 这个图标的正确术语是什么?
  • 它是 swift ui 工具/库的一部分还是只是一个 UIImage?
  • 有人可以提供一个关于如何实现的简单代码片段 - 也许类似于下面的代码
let sampleController = SampleController()
sampleController.POSSIBLE_OPTION_TO_SHOW_BAR_ICON = true
present(sampleController, animated: true, completion: nil)

Please see the red arrow for the icon that I am referring to

enter image description here

最佳答案

  1. 抓取器

grabber is a small horizontal indicator that can appear at the top edge of asheet.

In general, include a grabber in a resizable sheet. A grabber shows people that they can drag the sheet to resize it; they can alsotap it to cycle through the detents. In addition to providing a visualindicator of resizability, a grabber also works with VoiceOver sopeople can resize the sheet without seeing the screen. For developerguidance, see prefersGrabberVisible.

https://developer.apple.com/design/human-interface-guidelines/ios/views/sheets/

  1. iOS 15+ UISheetPresentationController 具有属性 prefersGrabberVisible https://developer.apple.com/documentation/uikit/uisheetpresentationcontroller/3801906-prefersgrabbervisible

A grabber is a visual affordance that indicates that a sheet isresizable. Showing a grabber may be useful when it isn't apparent thata sheet can resize or when the sheet can't dismiss interactively.

Set this value to true for the system to draw a grabber in thestandard system-defined location. The system automatically hides thegrabber at appropriate times, like when the sheet is full screen in acompact-height size class or when another sheet presents on top of it.

  • iOS 15 的 Playground 代码段:
  • import UIKit
    import PlaygroundSupport

    let viewController = UIViewController()
    viewController.view.frame = CGRect(x: 0, y: 0, width: 380, height: 800)
    viewController.view.backgroundColor = .white

    PlaygroundPage.current.liveView = viewController.view
    PlaygroundPage.current.needsIndefiniteExecution = true

    let button = UIButton(primaryAction: UIAction { _ in showModal() })
    button.setTitle("Show page sheet", for: .normal)
    viewController.view.addSubview(button)
    button.frame = CGRect(x: 90, y: 100, width: 200, height: 44)

    func showModal {
    let viewControllerToPresent = UIViewController()
    viewControllerToPresent.view.backgroundColor = .blue.withAlphaComponent(0.5)
    viewControllerToPresent.modalPresentationStyle = .pageSheet // or .formSheet
    if let sheet = viewControllerToPresent.sheetPresentationController {
    sheet.detents = [.medium(), .large()]
    sheet.prefersGrabberVisible = true
    }
    viewController.present(viewControllerToPresent, animated: true, completion: nil)
    }

    Grabber example

    关于ios - 快速呈现 Controller 关闭栏指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58382329/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com