可视化水龙头视图,显示水龙头指示器
问题描述:
我想添加水龙头,以专注于我的自定义相机视图,我设法做到这一点,但现在我需要显示的东西,使用户可以知道他实际上在做一些事情。 ......展示一个像苹果黄色广场或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
}
}
}
}
现在,我怎么添加自定义指标上触摸对焦?谢谢
答
在屏幕的其余部分顶部添加覆盖视图。然后你可以在draw()函数中绘制你的指标。每当你需要覆盖显示来更新时调用它的setNeedsDisplay()函数。在下面的例子中,我已经在设置函数中包含了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
}
}
}
因此,如果我将在draw func中添加图像,它会被看到? – RandomGeek
我已经扩展了示例代码,以显示如何在覆盖视图中绘制关于可变触摸点的正方形。 – Spads