gpt4 book ai didi

ios - 可视化点击 View ,显示点击指示器

转载 作者:行者123 更新时间:2023-11-28 15:26:20 27 4
gpt4 key购买 nike

我正在尝试添加点击以聚焦到我的自定义相机 View 上,我设法做到了,但现在我需要显示一些东西,以便用户可以知道他实际上正在做某事......显示一个 UI,如 Apple 的黄色正方形,或 SnapChat 的白色圆圈。自定义指标...

这是我的代码:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let screenSize = view.bounds.size
if let touchPoint = touches.first {
let x = touchPoint.location(in: view).y / screenSize.height
let y = 1.0 - touchPoint.location(in: view).x / screenSize.width
let focusPoint = CGPoint(x: x, y: y)

if let device = captureDevice {
do {
try device.lockForConfiguration()

device.focusPointOfInterest = focusPoint
//device.focusMode = .continuousAutoFocus
device.focusMode = .autoFocus
//device.focusMode = .locked
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
device.unlockForConfiguration()
}
catch {
// just ignore
}
}
}
}

现在如何在该点击上添加自定义指示器以聚焦?谢谢

最佳答案

在屏幕的其余部分之上添加一个叠加 View 。然后您可以在其 draw() 函数中绘制您的指标。每当您需要覆盖显示更新时调用其 setNeedsDisplay() 函数。在下面的示例中,我在设置函数中包含了 touchPoint。确保在此 View 上禁用用户交互,否则您的触摸将无法通过底层用户界面。

class OverlayView : UIView {

override func draw(_ rect: CGRect) {
// draw your touch indicator here
if let pt = _touchPoint {
let color:UIColor = UIColor.gray
let rect = CGRect(x:pt.x - 30, y:pt.y - 30, width:60, height:60)
let bpath:UIBezierPath = UIBezierPath(rect: rect)

color.set()
bpath.stroke()
}
}

private var _touchPoint : CGPoint?
var touchPoint : CGPoint? {
set(value) {
_touchPoint = value
setNeedsDisplay()
}
get {
return _touchPoint
}
}

}

关于ios - 可视化点击 View ,显示点击指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45168271/

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