AVCaptureDevice videoZoomFactor always Out of Range

守給你的承諾、 提交于 2019-12-06 12:25:41

According to apple documentation, if the device's videoMaxZoomFactor is 1, then zoom is not available:

If the device's videoZoomFactor property is assigned a larger value, an NSRangeException will be thrown. A maximum zoom factor of 1 indicates no zoom is available.

So in your case, you could hide the zoomButton by just checking this property:

AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
float max=videoDevice.activeFormat.videoMaxZoomFactor;

if (max==1) {
    [ZoomButton setHidden:YES];
}

You should check videoMaxZoomFactor before setting videoZoomFactor because videoZoomFactor is NOT always "from 1.0 to 2.0" . Docs:

This value is a multiplier. For example, a value of 2.0 doubles the size of an image’s subject (and halves the field of view). Allowed values range from 1.0 (full field of view) to the value of the active format’s videoMaxZoomFactor property. Setting the value of this property jumps immediately to the new zoom factor. For a smooth transition, use the rampToVideoZoomFactor:withRate: method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!