-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Camera | ||
|
||
A UI component that simplifies handling with camera. `PhotoCamera` & `QRCodeScanner`. | ||
|
||
## Usage | ||
|
||
### PhotoCamera Example: | ||
```swift | ||
let camera = PhotoCamera() | ||
func prepareCamera() { | ||
do { | ||
try await camera.prepare() | ||
} catch { | ||
// error handling | ||
} | ||
|
||
// add previewLayer to any view | ||
view.layer.addSublayer(camera.previewLayer) | ||
camera.previewLayer.frame = self.view.bounds | ||
|
||
// set camera delegate | ||
camera.delegate = self | ||
|
||
// request authorization status | ||
let granted = await camera.requestAuthorizationStatus() | ||
|
||
switch granted { | ||
case true: | ||
self.camera.startSession() | ||
case false: | ||
// handle denied status | ||
break | ||
} | ||
} | ||
``` | ||
#### Photo Camera functions | ||
`func takePhoto()` | ||
|
||
We can also switch from front facing to back camera: | ||
|
||
`func changeCamera(position: CameraPosition)` | ||
|
||
|
||
#### Photo Camera delegate | ||
|
||
`func photoCamera(photoCamera: PhotoCamera, didTakePhoto image: UIImage)` | ||
|
||
`func photoCamera(photoCamera: PhotoCamera, didTriggerError error: Camera.Error)` | ||
|
||
### QRCodeScanner Example: | ||
```swift | ||
let scanner = QRCodeScanner() | ||
func prepareQRCodeSCanner() { | ||
do { | ||
try await camera.prepare() | ||
} catch { | ||
// error handling | ||
} | ||
|
||
// add previewLayer to any view | ||
view.layer.addSublayer(scanner.previewLayer) | ||
scanner.previewLayer.frame = self.view.bounds | ||
|
||
// set camera delegate | ||
scanner.delegate = self | ||
|
||
// request authorization status | ||
let granted = await scanner.requestAuthorizationStatus() | ||
|
||
switch granted { | ||
case true: | ||
self.scanner.startSession() | ||
case false: | ||
// handle denied status | ||
break | ||
} | ||
} | ||
``` | ||
|
||
#### QRCodeScanner delegate | ||
`func codeScanned(code: String, boundingRect: CGRect)` | ||
|
||
`func scanFailure()` | ||
|
||
## Source code | ||
You can find source code [here](/Sources/Utilities/Camera). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters