I am using UIPanGesture to control the system brightness. Till now it was working well on iOS 15 to the previous version. But on iOS 16 the value only changes for one step.
Here is my code
@objc func panOnView(gesture: UIPanGestureRecognizer) {
let yTranslation = gesture.translation(in: gesture.view).y
let xTranslation = gesture.translation(in: gesture.view).x
// The slide distance needed to equal one value in the slider
// let tolerance: CGFloat = 20
if abs(yTranslation) >= abs(xTranslation) {
if (gesture.velocity(in: self.view).y > 0)
{
var brightness: Float = Float(UIScreen.main.brightness)
if(brightness >= 0.01 && brightness <= 1.00) {
brightness = brightness - 0.01
UIScreen.main.brightness = CGFloat(brightness)
}
// print("pan on down")
} else if (gesture.velocity(in: self.view).y < 0) {
var brightness: Float = Float(UIScreen.main.brightness)
if(brightness <= 0.99 && brightness >= 0.00 ) {
brightness = brightness + 0.01
UIScreen.main.brightness = CGFloat(brightness)
} else {
}
// print("pan on up")
}
gesture.setTranslation(.zero, in: gesture.view)
}
}
It doesn't seem to be a problem but you can try this code.