在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) } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。