반응형
카메라 플래시 On/Off 예제 코드입니다.
//카메라 디바이스 가져오기
guard let device = AVCaptureDevice.default(for: .video) else { return }
//플래시를 지원한다면
if device.hasTorch {
do {
try device.lockForConfiguration()
//현재 off상태이면 on시키기
if device.torchMode == .off {
device.torchMode = .on
//플래시 버튼 이미지 변경
self.flashBtn.setImage(UIImage.init(named: "icon_flash_off"), for: .normal)
}
//현재 on상태이면 off시키기
else {
device.torchMode = .off
//플래시 버튼 이미지 변경
self.flashBtn.setImage(UIImage.init(named: "icon_flash_on"), for: .normal)
}
device.unlockForConfiguration()
} catch {
print("Torch could not be used")
}
} else {
print("Torch is not available")
}
반응형
'아이폰' 카테고리의 다른 글
Swift Target 13미만 시 UIScene, UISceneConfigration, .. Error (0) | 2021.11.20 |
---|---|
Swift 쿠키(cookie) 동기화(URLRequest, WKWebView) (0) | 2021.11.20 |
Swift 타이머(Timer) 사용 (0) | 2021.11.20 |
Swift UIImageView + URL이미지 (0) | 2021.11.20 |
Swift 키보드 Show/Hide 이벤트, 화면 밖 터치로 내리기 (0) | 2021.11.20 |
최근댓글