gpt4 book ai didi

ios - 我如何为 Peek 和 Pop 3D Touch 圆化 sourceRect 的角?

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:18 26 4
gpt4 key购买 nike

在 Safari 中,如果您使用 3D 触摸,则被触摸的链接的 sourceRect 具有圆角。当我在以下位置设置源矩形时:func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {在 previewingContext 上,我只能设置 previewingContext.sourceRect,这不允许我圆角或设置多角区域。我该怎么做?

最佳答案

您可以通过向 sourceView 的层添加圆角半径来间接为 sourceRect 设置圆角。当您将 previewingContext.sourceRect 设置为 sourceView 的边界时,保持焦点的区域也将具有圆角。

这是一个使用可按下的 UILabel 的示例:

class ViewController: UIViewController {

var previewingContext: UIViewControllerPreviewing?
let label = UILabel(frame: CGRectMake(150, 250, 100, 50))

override func viewDidLoad() {
super.viewDidLoad()

let background = UIImageView(frame: view.bounds)
background.image = UIImage(named: "image.jpg")
view.addSubview(background)

label.backgroundColor = UIColor.whiteColor()
label.text = "Press me!"
label.textAlignment = .Center
label.layer.cornerRadius = 20
label.clipsToBounds = true
label.userInteractionEnabled = true
view.addSubview(label)

previewingContext = registerForPreviewingWithDelegate(self, sourceView: label)
}
}

extension ViewController: UIViewControllerPreviewingDelegate {

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
previewingContext.sourceRect = label.bounds

return UIViewController()
}

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
showViewController(viewControllerToCommit, sender: self)
}
}

enter image description here

关于ios - 我如何为 Peek 和 Pop 3D Touch 圆化 sourceRect 的角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34340664/

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