Sir*_*III 5 ios swift 3dtouch peek-pop
在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)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |