SwiftUI 2.0 Building Custom Camera - Custom Camera View - AVFoundation - SwiftUI Tutorials
HTML-код
- Опубликовано: 9 сен 2024
- In this Video i'm going to show how to Build a Custom Camera View Using SwiftUI 2.0 | SwiftUI Camera | SwiftUI Creating Custom Camera View | SwiftUI | SwiftUI Custom Camera Controller | SwiftUI Camera App | How to Access Camera In SwiftUI | SwiftUI AVFoundation | SwiftUI AVCaptureSession | Xcode 12 SwiftUI.
Source Code
kavsoft.dev/Sw...
Support Us By Contributions : donorbox.org/k...
Support Us By Patreon : / kavsoft
Support Us By Visiting the Link Given Below.
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. It's gives a great experience and I think you should give it a try too www.kite.com/g...
My Xcode Version is 12.2
My macOS Version is 11.0 Big Sur
For Any Queries And Any Request For Videos Use The Given Link
kavsoft.dev/#c...
For More
kavsoft.dev
Instagram
/ _kavsoft
Twitter
/ _kavsoft
Hi all. Firstly thank you Kavsoft for this tutorial. It was easy to follow and helped me better understand the logic behind this kind of app building. I had an issue where UIImage(data: self.picData)! throws a nul error on unwrapping. I narrowed it down to the takePic() function. What solved it for me is moving the self.session.stopRunning() line to after the DispatchQueue. It seems that as it was, that is exactly before the DispachQueue, caused the data to be lost. I don't know If what I'm saying is absolute heracy as I am just starting but just though I would share it in case someone else met with this issue.
Hey Andrew, I'm having the same problem. Can you please elaborate on how you fixed it please. Thanks
@@nedorourke7587 Getting the same thing did you get it?
Thanks! had the same problem and this fixed it
Nice in addition I added to remove additional force unwrapping:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5 {
self.session.stopRunning()
}
@@LDLefebvre thank you so much! I'm working on my bachelor's thesis and this specific problem has been driving me nuts for days!! now i can finally move on to the next one, haha
How to Building Custom record video - Custom Video View - AVFoundation - SwiftUI
Thank you so much for sharing the simple and straight forward example. Well done 👍
the preview on the right makes it so much easier to follow
Saving photo works on my Iphone but not for Ipad, could you please tell me how to do that? Thank you
Man you are great. Thanks a lot for these videos.
Thank you for your hard work, Sir!. This video helps me alot!
Thanks a lot for this tutorial. I was following along until I noticed that I was not getting "pic taken..." in the output. My guess was that photoOutput() was not being called. I found a workaround in stackoverflow by putting a timer in self.session.stopRunning() in the func takePic() in this way DispatchQueue.main.async { Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { (timer) in self.session.stopRunning() } } . Does anybody know why this was needed? is there a better solution?
thanks for helping me 😭😭
thanks man
@@apurvpandey2186
Great video!!!But How can I get a video from this Custom Camera?...
can u make a video about the feature of instagram to show the product by typing the photo ones??? pls
btw nice video !
Great video!!! Been looking forward to this one
Can we put a camera watermark doing this way ? because that's the only thing missing on ios...like in different formats such as:
Feb 21, 2024 2:40:33 PM EST (for example). Also is AVcam the same thing as ios Camera app ? how is it different or same ?
Thx brother
Thank you, for this channel! Very good code, and i use some your examples in my work!
I have some troubles on XCode 14.3.1 and target iOS 16+ 😭
Can you explain the issue?
@@Kavsoft 11:40 - about after that, I noticed that I was getting a purple warning.
At the same time, even at this stage, I did not receive a message in the console "pick taken..."
As far as I understand, these warnings are related to the new work of threads in SwiftUI 4+. Thank you!
struct CameraPreview: UIViewRepresentable {
@ObservedObject var camera: CameraModel
func makeUIView(context: Context) -> UIView {
let view = UIView(frame: UIScreen.main.bounds)
// WARNING! Publishing changes from within view updates is not allowed, this will cause undefined behavior.
camera.preview = AVCaptureVideoPreviewLayer(session: camera.session) //
I have the same issue
@@LukiStreli
@kavsoft The example video shows that the camera opens immediately by clicking on the app icon. How to activate the same code only through the button ("Button (action: { ... }, label: { ... ") ???. There is a button on the TabBar, this button should open the camera... I'm just learning and I can't find the answer... Help!)
@kavsoft I was wondering could make a video on how to block a user and in return the user that is blocked can view the (current userid) post or send them messages. I want to develop my skills to see how this works? Thank you
Kavsoft - when the screen is oriented, the camera borders break - how to fix it?? pls help
any idea?
Found a solution?
I had the same question and figured it out a solution. I added a binding var inside CameraView of type UIDeviceOrientation?. In the SwiftUI parent view, .onAppear() and .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) I set the orientation to UIDevice.current.orientation. This triggers the updateUIView() method to be called where you can reset the preview's frame and videoOrientationAngle.
Do you know if it is possible to somehow crop the captured image by detecting the rectangle? how to get only part of a card
Fantastic tutorial!
Hi Balaji, thanks for making this video! I have one problem I couldn't figure out and it's been bothering me for days. When I wrap the CameraPreview (which is a UIViewRepresentable) inside a NavigationView, the view takes more than 10 seconds to load. Could you please help me figure out why this is the case?
Update: The CameraPreview is a also a TabView Item.
when I try to go to my camera scene it freezes and gives me an error saying device found nil
I have the same issue. Any fix for this?
Update: I solved by only specifying the "for" parameter --> let device = AVCaptureDevice.default(for: .video)
@@pianoprodigy23 oh thanks, very helpful
@@pianoprodigy23 Thank you!
@@pianoprodigy23 Thanks :D
Great tutorial! Very helpful! Thank you!
Great Video
Great video! Thank you very much really appreciated 🙌🏻
Hi !!! Firstly thank you for video. I have issue when save image. This picture has saved not the lates images (n-1). And alway on the firts picture is empty. Pls help me resolve that, thanks you.
Awesome that is a very important video. Thanks.
Cool 🎉
I keep on running into 2 issues that Kees on saying that "CameraModel has no initializer", and that "type CameraModel cannot conform to ObservableObject" does anyone know how to fix this???
Just in case check whether you used struct instead of class for CameraModel?
for me I had forgotten "!" at the end of a variable, I had the same issue and this fixed it: @Published var preview: AVCaptureVideoPreviewLayer!
Hello, do you need to pay for the source code, I can't open it
Hello i'm watching your videos i want swiftui imageviewer with zoom and pinch
Did you found a way to do this?
About the CameraPreview, I came across issue.
camera.preview = AVCaptureVideoPreviewLayer(session: camera.session) //xcode said: Publishing changes from within view updates is not allowed, this will cause undefined behavior.
camera.preview.frame = view.frame
camera.preview.videoGravity = .resizeAspectFill
camera.session.startRunning() //xcode said: -[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness
view.layer.addSublayer(camera.preview)
xcode14.
Replace dispatchTask from .userInitiated to .background.
Also check out this updated version!
ruclips.net/video/_GGDueorwEA/видео.html
Thanks a lot@@Kavsoft
Where do you replace? I am having the same issue I can't find out still how to solve it. help!!@@Kavsoft
@@henna._.0396 me too
how come you guys never out film anything other then your keyboard SMH