swiftui

SwiftUI 2.0 TabView disable swipe to change page

蹲街弑〆低调 提交于 2021-01-23 06:37:52
问题 I have a TabView thats using the swiftUI 2.0 PageTabViewStyle. Is there any way to disable the swipe to change pages? I have a search bar in my first tab view, but if a user is typing, I don't want to give the ability to change they are on, I basically want it to be locked on to that screen until said function is done. Here's a gif showing the difference, I'm looking to disable tab changing when it's full screen in the gif. https://imgur.com/GrqcGCI 回答1: Try something like the following

Play reminder sound SwiftUI

孤街醉人 提交于 2021-01-21 11:47:28
问题 I understand I can play a sound from my own library, like: How to play a sound using Swift? But how can I use the already existing default Reminder Alerts sounds that iPhone has? Just to put it into context in a simple button press? Thanks 回答1: try this: import AVFoundation AudioServicesPlaySystemSound(1026) where the number 1026 is the SystemSound id. 来源: https://stackoverflow.com/questions/61310578/play-reminder-sound-swiftui

How to using realtime camera streaming in swiftui?

陌路散爱 提交于 2021-01-21 10:18:45
问题 I build a StreamingView like this: struct StreamingView: UIViewRepresentable { func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<StreamingView>) { // } func makeUIView(context: UIViewRepresentableContext<StreamingView>) -> UIView { let view = UIView() let captureSession = AVCaptureSession() captureSession.sessionPreset = .photo guard let captureDevice = AVCaptureDevice.default(for: .video) else { return view} guard let input = try? AVCaptureDeviceInput(device:

How to using realtime camera streaming in swiftui?

爷,独闯天下 提交于 2021-01-21 10:17:22
问题 I build a StreamingView like this: struct StreamingView: UIViewRepresentable { func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<StreamingView>) { // } func makeUIView(context: UIViewRepresentableContext<StreamingView>) -> UIView { let view = UIView() let captureSession = AVCaptureSession() captureSession.sessionPreset = .photo guard let captureDevice = AVCaptureDevice.default(for: .video) else { return view} guard let input = try? AVCaptureDeviceInput(device:

How to make List with single selection with SwiftUI 5

心不动则不痛 提交于 2021-01-21 08:43:05
问题 I am creating single selection list to use in different places in my app. Questions: Is there an easy solution I don't know? If there isn't, how can I finish my current solution? My goal: List with always only one item selected or one or none item selected (depending on configuration) Transparent background On item select - perform action which is set as parameter via init() method. (That action requires selected item info.) Change list data programmatically and reset selection to first item

Is there any way to set inputView for TextField in SwiftUI?

北慕城南 提交于 2021-01-21 08:40:02
问题 I want to set picker as my inputView for TextField, can I do it with SwiftUI only or I have to use UIKit components with help of framework integration? Code example in UIKit: textField.inputView = UIPickerView() I want to do same, but with SwiftUI's TextField 回答1: As of Xcode 11.4, SwiftUI's TextField does not have an equivalent of the inputView property of UITextField . You can work around it by bridging a UIKit UITextField to SwiftUI, and by bridging a SwiftUI Picker to UIKit. You'll need

Is there any way to set inputView for TextField in SwiftUI?

。_饼干妹妹 提交于 2021-01-21 08:38:24
问题 I want to set picker as my inputView for TextField, can I do it with SwiftUI only or I have to use UIKit components with help of framework integration? Code example in UIKit: textField.inputView = UIPickerView() I want to do same, but with SwiftUI's TextField 回答1: As of Xcode 11.4, SwiftUI's TextField does not have an equivalent of the inputView property of UITextField . You can work around it by bridging a UIKit UITextField to SwiftUI, and by bridging a SwiftUI Picker to UIKit. You'll need

Adding a TabView makes the Navigation Bar not cover the safe area in SwiftUI

你离开我真会死。 提交于 2021-01-21 08:25:41
问题 When adding a TabView in my SwiftUI iOS App, the Navigation Bar stops covering up the notch I've tried creating another file for the TabView implementation ( Modifying SceneDeletage and so on) Here is a simple code without TabView that makes the Navigation Bar cover the safe area (aka the notch) import SwiftUI struct ContentView: View { var body: some View { NavigationView{ ScrollView{ HStack{ VStack{ ForEach((1...10), id: \.self){_ in Text("Hello") .padding(.leading, 20) } } Spacer() //

SwiftUI iOS app crashes when state change causes keyboard to resign as first responder while in a sheet

萝らか妹 提交于 2021-01-21 07:09:44
问题 I'm trying to create a view in a sheet with multiple "pages". The view holds a @State variable of an enum and I "switch" between pages with if self.page == .text {...} else if self.page == .image {...} else {...} However, when self.page is set while a textfield is active in one of the pages, the app crashes with no clear error message. This seems to work on the simulator but not on a device. Here's the dump: Thread 1 Queue : com.apple.main-thread (serial) #0 0x00000001f6dc702c in

SwiftUI iOS app crashes when state change causes keyboard to resign as first responder while in a sheet

不羁岁月 提交于 2021-01-21 07:07:48
问题 I'm trying to create a view in a sheet with multiple "pages". The view holds a @State variable of an enum and I "switch" between pages with if self.page == .text {...} else if self.page == .image {...} else {...} However, when self.page is set while a textfield is active in one of the pages, the app crashes with no clear error message. This seems to work on the simulator but not on a device. Here's the dump: Thread 1 Queue : com.apple.main-thread (serial) #0 0x00000001f6dc702c in