HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何围绕sourceRect的角落来寻找Peek和Pop 3D Touch?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在Safari中,如果使用3D触摸,则正在触摸的链接sourceRect具有圆角.当我将源rect设置为:func previewingContext(previewingContext:UIViewControllerPreviewing,viewControllerForLOCATIOn LOCATIOn:CGPoint) – >的UIViewController? {on 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)
    }
}

ios – 如何围绕sourceRect的角落来寻找Peek和Pop 3D Touch?

大佬总结

以上是大佬教程为你收集整理的ios – 如何围绕sourceRect的角落来寻找Peek和Pop 3D Touch?全部内容,希望文章能够帮你解决ios – 如何围绕sourceRect的角落来寻找Peek和Pop 3D Touch?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。