我正在尝试添加水龙头以专注于我的自定义相机View并且我设法做到了但现在我需要展示一些东西以便用户可以知道他实际上正在做某事....显示像Apple的黄色的UI方形或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
}
}
}
}
现在如何在该水龙头上添加自定义指标以进行聚焦?感谢
答案 0 :(得分:1)
在屏幕的其余部分顶部添加叠加视图。然后,您可以在其draw()函数中绘制指标。每当您需要覆盖显示更新时调用其setNeedsDisplay()函数。在下面的例子中,我在touch函数中包含了touchPoint。确保在此视图上禁用用户交互,否则您的触摸将无法通过底层用户界面。
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
}
}
}