swiftui

How do I use the Google Mobile Ads SDK in SwiftUI, or use the UIKit UIViewController within a SwiftUI view?

十年热恋 提交于 2021-01-20 22:01:40
问题 I have a SwiftUI view that I want to open a rewarded ad from the Google Mobile Ads SDK when I press a button. The instructions for loading the ads (https://developers.google.com/admob/ios/rewarded-ads#create_rewarded_ad) are in UIKit, and I'm struggling to use them in my SwiftUI app. Is there a way to load the ads using SwiftUI, or if I use UIKit, how do I integrate it into SwiftUI? This is the SwiftUI parent view: struct AdMenu: View { var body: some View { NavigationView { NavigationLink

How do I use the Google Mobile Ads SDK in SwiftUI, or use the UIKit UIViewController within a SwiftUI view?

冷暖自知 提交于 2021-01-20 21:58:59
问题 I have a SwiftUI view that I want to open a rewarded ad from the Google Mobile Ads SDK when I press a button. The instructions for loading the ads (https://developers.google.com/admob/ios/rewarded-ads#create_rewarded_ad) are in UIKit, and I'm struggling to use them in my SwiftUI app. Is there a way to load the ads using SwiftUI, or if I use UIKit, how do I integrate it into SwiftUI? This is the SwiftUI parent view: struct AdMenu: View { var body: some View { NavigationView { NavigationLink

SwiftUI: Detect finger position on Mac trackpad

前提是你 提交于 2021-01-20 20:10:03
问题 I'm making a SwiftUI app for macOS and I'd like to use the trackpad as an (x, y) input by detecting the position of the user's fingers. I wanna be able to detect multiple fingers that are resting on the trackpad (not dragging). How do I do that? A similar question has been asked before, but I'm asking again because that was from nearly 10 years ago, the answers are all in Obj-C (one in Swift 3), and I'm wondering if there's an updated methodology. Most importantly, I've no clue how to

SwiftUI: Detect finger position on Mac trackpad

若如初见. 提交于 2021-01-20 20:09:51
问题 I'm making a SwiftUI app for macOS and I'd like to use the trackpad as an (x, y) input by detecting the position of the user's fingers. I wanna be able to detect multiple fingers that are resting on the trackpad (not dragging). How do I do that? A similar question has been asked before, but I'm asking again because that was from nearly 10 years ago, the answers are all in Obj-C (one in Swift 3), and I'm wondering if there's an updated methodology. Most importantly, I've no clue how to

SwiftUI: Detect finger position on Mac trackpad

人走茶凉 提交于 2021-01-20 20:08:31
问题 I'm making a SwiftUI app for macOS and I'd like to use the trackpad as an (x, y) input by detecting the position of the user's fingers. I wanna be able to detect multiple fingers that are resting on the trackpad (not dragging). How do I do that? A similar question has been asked before, but I'm asking again because that was from nearly 10 years ago, the answers are all in Obj-C (one in Swift 3), and I'm wondering if there's an updated methodology. Most importantly, I've no clue how to

SwiftUI: Detect finger position on Mac trackpad

两盒软妹~` 提交于 2021-01-20 20:06:35
问题 I'm making a SwiftUI app for macOS and I'd like to use the trackpad as an (x, y) input by detecting the position of the user's fingers. I wanna be able to detect multiple fingers that are resting on the trackpad (not dragging). How do I do that? A similar question has been asked before, but I'm asking again because that was from nearly 10 years ago, the answers are all in Obj-C (one in Swift 3), and I'm wondering if there's an updated methodology. Most importantly, I've no clue how to

Dismiss a SwiftUI View that is contained in a UIHostingController

天大地大妈咪最大 提交于 2021-01-20 19:00:07
问题 I have rewritten my sign in view controller as a SwiftUI View . The SignInView is wrapped in a UIHostingController subclass ( final class SignInViewController: UIHostingController<SignInView> {} ), and is presented modally, full screen, when sign in is necessary. Everything is working fine, except I can't figure out how to dismiss the SignInViewController from the SignInView . I have tried adding: @Environment(\.isPresented) var isPresented in SignInView and assigning it to false when sign in

Dismiss a SwiftUI View that is contained in a UIHostingController

混江龙づ霸主 提交于 2021-01-20 18:56:20
问题 I have rewritten my sign in view controller as a SwiftUI View . The SignInView is wrapped in a UIHostingController subclass ( final class SignInViewController: UIHostingController<SignInView> {} ), and is presented modally, full screen, when sign in is necessary. Everything is working fine, except I can't figure out how to dismiss the SignInViewController from the SignInView . I have tried adding: @Environment(\.isPresented) var isPresented in SignInView and assigning it to false when sign in

How to log Firebase Analytics screen name in a SwiftUI app?

∥☆過路亽.° 提交于 2021-01-20 16:54:24
问题 I'm trying to log screen names in my app but I have like 95% not set in Firebase Analytics. In onAppear for a view I do Analytics.setScreenName("screenName", screenClass: "screenName") Should I do this differently? It seems that Analytics for iOS works in conjunction with UIViewController s but since this a SwiftUI app and there is no documentation on how to work with that. 回答1: We are working on a better solution for this. As you mentioned, the way the view controller hierarchy of a SwiftUI

How to add a TextField to Alert in SwiftUI?

血红的双手。 提交于 2021-01-20 16:23:59
问题 Anyone an idea how to create an Alert in SwiftUI that contains a TextField? 回答1: As the Alert view provided by SwiftUI doesn't do the job you will need indeed to use UIAlertController from UIKit . Ideally we want a TextFieldAlert view that we can presented in the same way we would present the Alert provided by SwiftUI : struct MyView: View { @Binding var alertIsPresented: Bool @Binding var text: String? // this is updated as the user types in the text field var body: some View { Text("My Demo