OGeek|极客世界-中国程序员成长平台

标题: ios - 相机对焦ios [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:34
标题: ios - 相机对焦ios

我有崩溃消息:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Setting focusPointOfInterest is not supported by this device. Use isFocusPointOfInterestSupported'

代码后:

-(void)touchesBeganNSSet *)touches withEventUIEvent *)event
{
    [device setFocusPointOfInterest:CGPointMake(100, 100)];
}

有没有办法像相机胶卷那样进行对焦?



Best Answer-推荐答案


答案的组合,但这应该可以帮助您。

您需要将触摸点从触摸开始或触摸手势转换为 0-1 比例。

所以,检查你的设备是否有焦点,然后转换点:

-(void)touchesBeganNSSet *)touches withEventUIEvent *)event
{
    // get device reference...

    if ([device isFocusPointOfInterestSupported]) {
        CGPoint point = [touch locationInView:self.myCameraView];
        float newX = point.x / self.myCameraView.frame.size.width;
        float newY = point.y / self.myCameraView.frame.size.height;
        [device setFocusPointOfInterest:CGPointMake(newX, newY)];
    }
    else {
        // Focus not supported
    }
}

关于ios - 相机对焦ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15366550/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4