Post

Replies

Boosts

Views

Activity

Using WebKit Delegates
Hi,How would I go about using the standard WebKit delegates in SwiftUI, such as:func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { activityView?.startAnimating() self.title = "Loading...." }Here's what I have so far:import SwiftUI import UIKit import Foundation import WebKit struct Support: View { var body: some View { NavigationView { VStack { WebView(request: URLRequest(url: URL(string: "https://www.connectingpeoplesoftware.com/iossupport")!)) }.navigationBarTitle(Text("Support")) } } struct WebView: UIViewRepresentable { let request: URLRequest func makeUIView(context: Context) -> WKWebView { return WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { uiView.load(request) } } struct Support_Previews: PreviewProvider { static var previews: some View { Support() } } }Thanks in advance,Dan
3
0
6.4k
Dec ’19
Weird problem while in Landscape Mode
Hi,My app has been rejected three times now for this stupid problem that shouldnt be and I was wondering if anyone else has this problem with SwiftUI.I rewrote an app, and it works in Portriate Mode. But when I make it into Landscape, the display disappers. The app displays a normal List view with options and includes a Navigation Link.When a user selects an option and goes into the detail view, the same thing happens.This problem is on the simulator AND an external device (iPhone XS Max and an 2018 iPad Pro).Any ideas?Thanks,Dan Uff
2
0
1.4k
Dec ’19
.navigationViewStyle(StackNavigationViewStyle()) Not Working!
Hi,My app has gotten rejected four times for this problem so bear with me....A few weeks ago, I posted that I was having problems with my app showing a blank screen when someone went into Landscape Mode.Someone suggested using .navigationViewStyle(StackNavigationViewStyle()) which seemed to work the first few times, and then stopped working after I sent it to have it reviewed.I'm still having the same problem and it is becoming maddening.Here's the code in question (again):import SwiftUI import Foundation struct ContentView: View { var body: some View { NavigationView() { List (){ Section(header: Text("Main Information")) { NavigationLink(destination: Introduction()) { Image(systemName: "exclamationmark.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Introduction").tag(1) .font(.headline) } NavigationLink(destination: Definitions()) { Image(systemName: "questionmark.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Definitions").tag(2) .font(.headline) } NavigationLink(destination: TypesOfAbuse()) { Image(systemName: "table").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Types").tag(2) .font(.headline) } NavigationLink(destination: Effects()) { Image(systemName: "exclamationmark.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Effects").tag(2) .font(.headline) } NavigationLink(destination: WhereAbuseOccures()) { Image(systemName: "questionmark.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Where it Occurs").tag(3) .font(.headline) } NavigationLink(destination: RecognizingChildAbuse()) { Image(systemName: "xmark.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Recognizing Abuse").tag(4) .font(.headline) } NavigationLink(destination: ReportingSuspectedChildAbuse()) { Image(systemName: "phone.arrow.right").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Reporting Child Abuse").tag(5) .font(.headline) } NavigationLink(destination: ChildrenCanBeHelped()) { Image(systemName: "person.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Children Can Be Helped").tag(7) .font(.headline) } NavigationLink(destination: CountryMenu()) { Image(systemName: "phone.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Phone Numbers").tag(8) .font(.headline) } NavigationLink(destination: Search()) { Image(systemName: "magnifyingglass.circle").resizable() .frame(width: 32, height: 32, alignment: .leading) Text("Search").tag(9) .font(.headline) } } Section(header: Text("App Information & Support")) { NavigationLink(destination: About()) { Text("About").fontWeight(.bold) } NavigationLink(destination: Support()) { Text("Support").fontWeight(.bold) } } Section(header: Text("Version")) { Text("1.0").fontWeight(.bold) } } .navigationViewStyle(StackNavigationViewStyle()) .navigationBarTitle(Text("Child Abuse")) .listStyle(GroupedListStyle()) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { Group { ContentView() .previewDevice("iPhone XS Max") .environment(\.colorScheme, .light) } } } } extension View { func phoneOnlyStackNavigationView() -> some View { if UIDevice.current.userInterfaceIdiom == .phone { return AnyView(self.navigationViewStyle(StackNavigationViewStyle())) } else { return AnyView(self) } } }As you can see on line 126, I have the suggested option.By the way, lines 149 - 157 were from a website to try and get this working, but to no advail.Thanks,Dan Uff
9
0
4.9k
Jan ’20
Apple TV and SwiftUI
Hi,I'm trying to slowly add SwiftUI ViewControllers to an existing UIKit app.With the iPhone and iPad and using a storyboard and hostingcontroller, I use the below code to go from a UIKit ViewController to a SwiftUI view:@IBSegueAction func SwiftUIAction(_ coder: NSCoder) -> UIViewController? { return UIHostingController(coder: coder, rootView: SecondController())The above code does NOT work with the AppleTV, and it doesn't give me an error (or I would put it here) What am I missing?Thanks,Dan Uff
0
0
564
Jan ’20
Flipping an UIImage
Hi all,I'm making an app that I have to have a flip animation when someone taps a button.Here's the code:import WatchKit import Foundation class InterfaceController: WKInterfaceController { @IBOutlet var coin: WKInterfaceImage! @IBOutlet var txt: WKInterfaceLabel! override func awake(withContext context: Any?) { super.awake(withContext: context) txt.setText("Heads or Tails?") } @IBAction func CallIt() { let array = ["Heads","Tails"] let randomIndex = Int(arc4random_uniform(UInt32(array.count))) if randomIndex == 1 { let up = UIImage(named: "Heads") coin.setImage(up) txt.setText("Heads") }else { let down = UIImage(named: "Tails") coin.setImage(down) txt.setText("Tails") } } }Thanks in advance,Dan Uff
4
0
845
Feb ’20
Heads or Tails Game, What's Wrong?
Hi,I'm trying to convert an already Swift 5 game to SwiftUI. Almost everything works except when it's time to change the image based on the choice. Here's the code:import SwiftUI import Foundation struct ContentView: View { @State private var randomIndex: Int = 0 var body: some View { VStack() { Image("TwoSides") .resizable() .frame(width: 170, height: 90, alignment: .center) .position(x: 100, y: 40) Text("Heads or Tails").fontWeight(.bold) .frame(width: CGFloat(200), height: CGFloat(5), alignment: .center) .position(x: 90, y: 40) Button(action: { let array = ["Heads","Tails"] let randomIndex = Int(arc4random_uniform(UInt32(array.count))) if (randomIndex == 1) { print("Heads") Image("Heads") .resizable() .frame(width: 170, height: 90,alignment: .center) }else { print("Tails") Image("Tails") .resizable() .frame(width: 170, height: 90,alignment: .center) .position(x: 100, y: 40) } }) { VStack { Text("Flip Coin") .padding(15) .background(Color.green) .foregroundColor(Color.white) } } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }Any ideas would be greatful.Dan Uff
8
0
1.6k
Mar ’20
Strange warning in SwiftUI BUT the Code works!
Hi,I'm getting the following warning when I compile my test app:Braces here form a trailing closure separated from its callee by multiple newlines.Here's the code. Note where the warning is appearing..../* How to present an alertView in SwiftUI */ import SwiftUI struct ContentView: View { @State private var showSheet = false var body: some View { VStack { Text("Click below for an Alert") .fontWeight(.bold) .font(.largeTitle) Button(action: { self.showSheet = true } ) { Text("Click Me") .bold() .foregroundColor(.white) .background(Color.red) .font(.largeTitle) .padding() } .alert(isPresented: $showSheet) { // <---- The warning is HERE. Alert(title: Text("Alert"), message: Text("About **** time"), dismissButton: .default(Text("OK"))) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } }Thanks in advance,Dan Uff
1
0
907
Apr ’20
Controlling window size on Mac
Hi,I am trying to write my first Mac app with SwiftUI. I have everything working, but when the app comes up, it only shows half of the app. I have to manually size the window each time the app is run.How do I adjust the size so the entire app can be viewed at one time?Thanks,Dan Uff
7
0
7.4k
May ’20
SwiftUI Shifting Display Left
Hi,I have been trying to makean app with SwiftUI. Everything works, but when the app is shown on the screen (iPhone or iPad) everything is shifted to the left, dispite using GeometryReader.Such as:What I need:---> Centered <---What is displayed:<--- Everything shifted to the left.Any ideas?Dan Uffimport SwiftUI import AVFoundation import AVKit struct Middle: View { @State private var txtInput: String = "" @State private var txtEmpty = false var body: some View { GeometryReader() {_ in ZStack { Color.init(red: 0, green: 0, blue: 1) .edgesIgnoringSafeArea(.all) } VStack (alignment: .center){ Text("What would you like to say?") .bold() .font(.custom("Times New Roman", size: 27)) .foregroundColor(Color.white) .multilineTextAlignment(.center) .accessibility(hint: Text("Type what you want to say here. Tap Return when Finished.")) TextField("Tap here to start.", text: self.$txtInput) .background(Color .white) .frame(width: 320, height: 50, alignment: .leading) .font(.custom("ChalkBoard", size: 30)) .textFieldStyle(RoundedBorderTextFieldStyle()) .multilineTextAlignment(.leading) .keyboardType(.default) .accessibility(hint: Text("Start typing here.")) // Count text as the user types: Text("Word Count: \(self.txtInput.count)") .bold() .font(.custom("Chalkboard", size: 30)) .foregroundColor(Color.white) Button(action: { if self.txtInput.isEmpty { let toSay = AVSpeechUtterance(string: "I have nothing to say. Type something in the text area above the speaker button.") let alex = AVSpeechSynthesizer() alex.speak(toSay) }else { let toSay = AVSpeechUtterance(string: self.txtInput) let alex = AVSpeechSynthesizer() alex.speak(toSay) } }) { VStack(alignment: .center) { Image(systemName: "speaker.2") .resizable() .frame(width: 80, height: 45) .foregroundColor(Color.white) .accessibility(hint: Text("Tap speaker to talk.")) .padding(20) .background(Color.green) .padding() .clipShape(Rectangle()) .buttonStyle(PlainButtonStyle()) } // Clear Button: Button(action: { // }) { Text("") .font(.largeTitle) .foregroundColor(Color.white) } Image(systemName: "trash") .resizable() .frame(width:70, height: 45) .foregroundColor(Color.white) .accessibility(hint: Text("")) .padding(20) .background(Color.green) .padding() .clipShape(Rectangle()) .buttonStyle(PlainButtonStyle()) .onTapGesture { self.txtInput = "" }.padding() }.padding() } } } struct Middle_Previews: PreviewProvider { static var previews: some View { Middle() } } }
2
0
3.5k
May ’20
Getting ready to distribute first Mac App!
Hi,I've been an iOS developer for many years, and have just written my first Mac App (thank you SwiftUI) and am getting ready to distribute it to the Mac App Store.I want to know if I need to do anything else to the Mac App, other then doing the usual bundling for the app store, such as creating a setup app, or can I distribute it like an iOS app, and anything else that I'd need to know? (Yes, I did read all the docs I could find on this subject).Thanks,Dan Uff
5
0
1.1k
May ’20
Unable to play sound file when button is tapped
Hi,My app is a simple one, where someone taps on a button and a sound file is activated. But when that's done, the sound file doesnt activate.Here's the code:import SwiftUI import AVFoundation struct ContentView: View { private var autoPlayer: AVAudioPlayer = AVAudioPlayer() var body: some View { GeometryReader { _ in ZStack { Color.black .edgesIgnoringSafeArea(.all) Circle() .frame(width: 400, height: 400) .foregroundColor(Color.white) Circle() .frame(width: 340, height: 500) .foregroundColor(Color.red) Button(action: { print("Button Tapped!") let path = Bundle.main.path(forResource: "siren", ofType: "mp3")! do { let playFile = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) playFile.play() } catch { print(error) } }) { Text("Tap HERE for Alarm") .font(.largeTitle) .foregroundColor(Color.white) .bold() .italic() } } }.navigationBarTitle(Text("Personal Alarm")) } func playSound() { print("Button Tapped!") let path = Bundle.main.path(forResource: "siren.mp3", ofType: nil)! let url = URL(fileURLWithPath: path) do { let soundFile = try AVAudioPlayer(contentsOf: url) soundFile.play() } catch { print("Cannot Play Sound File!") } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }Any ideas?Dan Uff
4
1
3.1k
Jun ’20
Two apps, same framework, crash
Hi,I have two iOS apps that use the AVFoundation framework for speech.Everything works fine. But if I go from one app into the other with the same framework, that app crashes, even if I take the other app out of memory.The two apps are using two different voices as well.While it would be almost impossible for a user to have the two apps on the same device, one never knows :-)Any ideas?Dan Uff
1
0
558
Jun ’20