Post

Replies

Boosts

Views

Activity

Place Text on top of lines separating the colors
Hi, this is my custom view struct MyView: View {   var body: some View {     GeometryReader { geometryReader in       ZStack {         VStack(spacing: 0) {           Rectangle()             .fill(.red)             .frame(height: geometryReader.size.height * 0.25)                       Rectangle()             .fill(.orange)             .frame(height: geometryReader.size.height * 0.5)                       Rectangle()             .fill(.yellow)             .frame(height: geometryReader.size.height * 0.25)         }                   VStack {           Spacer()           Image(systemName: "figure.wave")             .resizable()             .aspectRatio(contentMode: .fit)             .frame(height: geometryReader.size.height * 0.8)         }       }     }     .frame(maxWidth: 100, maxHeight: 200)     .background(.white.opacity(0.7))     .cornerRadius(5)     .shadow(color: Color.gray.opacity(0.7), radius: 8, x: 0, y: 0)     .padding()   } } struct MyView_Previews: PreviewProvider {   static var previews: some View {     MyView()   } } I am not sure what the best approach for this is. I want to place some text (please see image). I was thinking adding another VStack at the bottom but i am not sure how i can position it correctly. Thoughts?
1
0
397
Dec ’22
Slide View Does Not Animate. But Fade Works.
Hi. I am having problems with animating my view sliding in and out and hiding if not in view. The thing is, fading in and out works. but moving it does not. What could be wrong or what Am i missing? import SwiftUI struct MyView: View {       @Binding var isShowing: Bool       var body: some View {     VStack(spacing: 0) {       Group {         row("#ff0000", "color1")         row("#ff0000", "color2")         row("#ff0000", "color3")         row("#ff0000", "color4")         row("#ff0000", "color5")         row("#ff0000", "color6")       }       Group {         row("#ff0000", "color7")         row("#ff0000", "color8")         row("#ff0000", "color9")         row("#ff0000", "color10")         row("#ff0000", "color11")         row("#ff0000", "color12")       }     }     .frame(maxWidth: 130, maxHeight: 250)     .background(.white.opacity(0.7))     .padding() //    .transition(.move(edge: isShowing ? .leading : .trailing))     .opacity(isShowing ? 1 : 0)     .animation(isShowing ? .easeIn(duration: 0.7) : .easeOut(duration: 0.7), value: isShowing)   }       private func row(_ color: String, _ labelKey: String) -> some View {     return HStack {       Rectangle()         .fill(Color(UIColor(hex: color)))         .frame(width: 15, height: 15)         .padding(.leading, 3)       Text(labelKey.uppercased())         .foregroundColor(.black)       Spacer()     }   } } and this is how to use the view var body: some View { @State private var isShowing = true HStack {     Button("click me", action: { isShowing.toggle() }) .padding() } .frame(maxWidth: .infinity, maxHeight: .infinity)     .overlay(       MyView(isShowing: $isShowing),       alignment: .bottom     ) }
1
0
400
Dec ’22
Is it possible to rebuild overlay only and not the body?
Hi. I am not sure how to do this case scenario I am having. Please see sample code @State private var tileLayers: [GMSURLTileLayer]?    @State private var isShowingLegend = true     var body: some View {     MapView(       tileLayers: tileLayers     )     .task {       setupMenuItems()               if load {         load = false         processRainWatcher()       }     }     .overlay(       isShowingLegend ?         HStack {           RainWatcherLegendView()           Spacer()         }         .transition(.move(edge: isShowingLegend ? .leading : .trailing))       : nil,       alignment: .bottom     ) } This is not a working code. But i wish to ask suggestion. because the overlay shows a legend view. If isShowingLegend.toggle() is triggered, it animates sliding in and out of the screen. Problem mis, everything gets rebuilt. so the tile layer in the MapView() gets re-rendered again. is there a way not to let this happen, but still let the legend animate sliding in and out? or perhaps pass a binding variable to the legend view? and do the animation in that view? so that the parent view does not get rebuilt? thoughts?
2
0
548
Nov ’22
Stepper is still buggy?
Anyone experienced this. My goal is to use AppStorage to save the value in the stepper but the behavior is whaked. Buttons get disabled even when theyre not at both ends of the array if i use State, it works a bit better but the buttons only get disabled after the 2nd or 3rd try when the index is either 0 or at the end of the array. @AppStorage("index") private var opacity = 0 let options = [40, 50, 70, 80, 90, 100]         Stepper {           Text("\("Opacity") \(options[opacity].description)%")         } onIncrement: {           opacity = opacity + 1           if opacity >= opacity.count {             opacity = opacity.count - 1           }           print("onincrement="+String(opacity))         } onDecrement: {           opacity = opacity - 1           if opacity < 0 {             opacity = 0           }           print("ondecrement="+String(opacity))         } The sample code looks simple. I am not sure what else I could be missing?
2
0
397
Nov ’22
How To Use Objective C Library In Swift Project
Hi all. I need help with this as i struggled to actually use the objective c library. https://github.com/ngageoint/simple-features-geojson-ios It says install from cocoapods. check. I got it. My issue is with the bridging header. I do not understand the posts and answers that I came across in stackoverflow. do i not need to install the library from cocoapods? instead copying the .h and .m to my swift project? And thereby generating that bridging header file? So i did just that and set #import "sf-geojson-ios-Bridging-Header.h" in the bridging header file. But when i build it, i keep getting the error message Build input file cannot be found: project-Bridging-Header.h'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? what is the correct way to do this? am i missing something?
1
0
676
Nov ’22
How To Open New Window When GMSMarker Info Window is Clicked in SwiftUI
I have managed to do tasks when an info window of a GMSMarker is clicked. This is where the magic happens func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) However, this time, I wish to open a custom view as a new window. I have not seen any helpful posts so I decided to try and ask the question here if anyone has experienced doing so. My goal is when the info window is clicked, i wish to open my custom view as a new window. Currently, I only know NavigationView and NavigationLink when opening up new windows but I am not sure how to use this in a GMSMarker info window click event. Thoughts?
0
0
291
Nov ’22
How To Loop Video In SwiftUI
Anyone got sample code for using AVPlayerLooper in SwiftUI? Code i see are not for SwiftUI I only wish to have the option to turn on auto-repeat on and off. I could use AVQueuePlayer as replacement for AVPlayer but it does not have a way to loop. So these are what I am looking for Loop video in SwiftUI If Using AVPlayerLooper, it has a disableLooping() function (possibly to turn off looping). But how can it be turned back on? There is no enableLooping(). Or does it need a new instance? since i am new to iOS, the code there are all linked to no swift ui code so I have no clue (sorry) the equivalent of them in SwiftUI Thoughts?
2
0
2.9k
Nov ’22
Why AVPlayer always nil
I do not understand why AVPlayer is always nil  Unexpectedly found nil while unwrapping an Optional value struct SatelliteVideoView: View {       init() {     player = AVPlayer(url: URL(string: "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4")!) }       var body: some View {     VideoPlayer(player: player!) } The documentation uses this code.
7
0
786
Nov ’22
TabView Reloads all Tab
I wish to ask suggestion on how to avoid this. i dont want every tab switch to reload the component..worse, fetch from url s this where mvvm comes in? so that even if component is reloaded, the mvvm data will be used? i think it is overkill though. my first and 3rd tab fetches data and loads markers in a map. my 2nd tab is a wkwebview that loads a url i noticed that whej i switch to the 3rd tab, the 1st tab gets reloaded still. thoughts on how to avood reloading? also tried setting tag to each tab item and setting a state variable to tab view to keep track of tab switching. to no avail. thoughts?
4
0
1.3k
Nov ’22
LocationManager Error when requesting location
Hi . I am following the simple example from hacking with swift website. It is to request a location. import CoreLocation import CoreLocationUI class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {   let manager = CLLocationManager()   @Published var location: CLLocationCoordinate2D?   override init() {     super.init()     manager.delegate = self   }   func requestLocation() {     manager.requestLocation()   }   func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {     print("hehe")     location = locations.first?.coordinate   } } In the view. I have some custom button that when clicked, will call locationManager.requestLocation() but it gives this error message Updates[14291:194102] *** Assertion failure in -[CLLocationManager requestLocation], CLLocationManager.m:1339 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to locationManager:didFailWithError:' *** First throw call stack: ( 0  CoreFoundation           0x0000000111b3a8cb __exceptionPreprocess + 242 1  libobjc.A.dylib           0x000000010d4efba3 objc_exception_throw + 48 2  Foundation             0x0000000116b3837c _userInfoForFileAndLine + 0 3  CoreLocation            0x000000010c1baf65 CLClientStopVehicleHeadingUpdates + 52782 7  SwiftUI               0x0000000113c6f5dc __swift_memcpy160_4 + 113486 8  SwiftUI               0x0000000113c6fe8d __swift_memcpy160_4 + 115711 9  SwiftUI               0x0000000113c6fdff __swift_memcpy160_4 + 115569 10 SwiftUI               0x00000001140a4270 objectdestroy.142Tm + 41347 11 SwiftUI               0x00000001140a4284 objectdestroy.142Tm + 41367 12 SwiftUI               0x00000001140a4270 objectdestroy.142Tm + 41347 13 SwiftUI               0x0000000113dba491 block_destroy_helper + 36990 14 SwiftUI               0x0000000113db9df2 block_destroy_helper + 35295 15 SwiftUI               0x0000000113f4b7a5 _callVisitToolbarContentType2 + 4011 16 SwiftUI               0x00000001146fa7c8 _callVisitStyleContextType2 + 11258 17 SwiftUI               0x00000001146f8e5e _callVisitStyleContextType2 + 4752 18 SwiftUI               0x00000001146f8f42 _callVisitStyleContextType2 + 4980 19 SwiftUI               0x00000001146f8720 _callVisitStyleContextType2 + 2898 20 UIKitCore              0x0000000120b384b9 -[UIGestureRecognizer _componentsEnded:withEvent:] + 153 21 UIKitCore              0x00000001211d7ebd -[UITouchesEvent _sendEventToGestureRecognizer:] + 662 22 UIKitCore              0x0000000120b286f7 -[UIGestureEnvironment _updateForEvent:window:] + 469 23 UIKitCore              0x000000012117aedb -[UIWindow sendEvent:] + 5282 24 UIKitCore              0x000000012114e7f2 -[UIApplication sendEvent:] + 898 25 UIKitCore              0x00000001211f5e61 __dispatchPreprocessedEventFromEventQueue + 9381 26 UIKitCore              0x00000001211f8569 __processEventQueue + 8334 27 UIKitCore              0x00000001211ee8a1 __eventFetcherSourceCallback + 272 28 CoreFoundation           0x0000000111a9a035 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 29 CoreFoundation           0x0000000111a99f74 __CFRunLoopDoSource0 + 157 30 CoreFoundation           0x0000000111a997d1 __CFRunLoopDoSources0 + 308 31 CoreFoundation           0x0000000111a93e73 __CFRunLoopRun + 927 32 CoreFoundation           0x0000000111a936f7 CFRunLoopRunSpecific + 560 33 GraphicsServices          0x000000011985b28a GSEventRunModal + 139 34 UIKitCore              0x000000012112d62b -[UIApplication _run] + 994 35 UIKitCore              0x0000000121132547 UIApplicationMain + 123 36 SwiftUI               0x00000001146b2cfb __swift_memcpy93_8 + 10826 37 SwiftUI               0x00000001146b2ba8 __swift_memcpy93_8 + 10487 38 SwiftUI               0x0000000113d68b7d __swift_memcpy195_8 + 12271 41 dyld                0x000000010be3d2bf start_sim + 10 42 ???                 0x0000000203a3d310 0x0 + 8651002640 ) libc++abi: terminating with uncaught exception of type NSException Message from debugger: Terminated due to signal 6 I really have no clue what is going on. It does not enter some breakpoint, it just crashes. Anything I am missing? Also, i could not find anything in the LocationManager regarding a callback when the location is retrieved? or it is a manual workaround that has to be done for this case? the issue may be because i need to include the function func locationManager( _ manager: CLLocationManager, didFailWithError error: Error ) but adds another question. Why do i get Error Domain=kCLErrorDomain Code=1 "(null)"
3
1
1.5k
Nov ’22
AttributeGraph: cycle detected through attribute In Sheet
Hi. I am not sure why i get the error message AttributeGraph: cycle detected through attribute but this does happen i noticed if i have a Text component render html. Here is the code import SwiftUI struct ContentView: View {   @State private var isShowingAlertSheet = false   @State private var alertTitle: String?   @State private var alertDescription: String?       var body: some View {     VStack {       Button(         "click me", action: {           alertTitle = "TITLE HERE"           alertDescription = "<b>hey</b>"           isShowingAlertSheet = true         }       )     }     .sheet(isPresented: $isShowingAlertSheet) {       DetailView(alertTitle: $alertTitle, alertDescription: $alertDescription)     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } struct DetailView: View {       @Binding var alertTitle: String?   @Binding var alertDescription: String?       var body: some View {     VStack {       Text(alertTitle ?? "")         .font(.system(size: 20))         .padding(.top, 10)         .padding(.bottom, 0)         .presentationDetents([.height(250)])       Text(fixTextSize(alertDescription?.htmlMutableAttributedString))         .frame(maxWidth: .infinity)         .padding(.top, 10)       Spacer()     }     .padding()   }       func fixTextSize(_ mutableAttributedString: NSMutableAttributedString?) -> AttributedString {     if let mutableAttributedString {       mutableAttributedString.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 16), range: NSMakeRange(0, mutableAttributedString.length))       return AttributedString(mutableAttributedString)     }     return AttributedString()   } } extension String {   var htmlMutableAttributedString: NSMutableAttributedString? {     if let attributedString = try? NSMutableAttributedString(data: Data(self.utf8), options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) {       attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(.black), range: NSMakeRange(0, attributedString.length))       return attributedString     }     return nil   } } Thoughts?
0
0
967
Nov ’22
Why does @Binding Force you To Declare it as Param?
A sample struct code struct Test { @Binding var name: String? } Why does it force me to have to instantiate it with Test(name: "blabla") Is there a way to not have to initialize this in the param? since It is an optional type. Binding<String?> works differently from @Binding, so ive read. Though one can do Binding<String?>? or is this the only possible way to do it?
0
0
276
Nov ’22
How To Use Call A BInding Variable From A GMSMapViewDelegate Coordinator
Hi, asking this here because this is not about google maps ios sdk issue but regarding the use of binding. My map view currently looks simple. import SwiftUI import GoogleMaps import GoogleMapsUtils struct MapView: UIViewRepresentable {       var geoJsonParser: GMUGeoJSONParser?       func makeUIView(context: Self.Context) -> GMSMapView {     let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: GMSCameraPosition())     mapView.delegate = context.coordinator     return mapView   }       func updateUIView(_ mapView: GMSMapView, context: Context) {     mapView.clear()           if let geoJsonParser {       print(geoJsonParser.features)     }   }       func makeCoordinator() -> Coordinator {     Coordinator(owner: self)   }     } class Coordinator: NSObject, GMSMapViewDelegate {      let owner: MapView       init(owner: MapView) {     self.owner = owner   }       func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {     print("tapped at coordinate")     print(owner)   } } class Coordinator: NSObject, GMSMapViewDelegate {      let owner: MapView       init(owner: MapView) {     self.owner = owner   }       func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {     print("tapped at coordinate")     print(owner.geoJsonParser)   } } My question is when i tap on the map, the mapView didTapAtCoordinate gets called but the geoJsonParser variable is always nil. So I thought i would use Binding in this case since when the MapView struct is used, I pass a @State geoJsonParser to its parameter. My question is, from within the MapView struct, I am not sure what else I could be lacking so that print(owner.geoJsonParser) will not return nil I tried to set the variable to var geoJsonParser: Binding? = nil But after tapping on the map and the mapView didTapAtCoordinate is called, print(owner.geoJsonParser) returns an error Cannot convert value of type 'Binding<[any GMUGeometryContainer]>' to expected argument type '[any GMUGeometryContainer]' Same error message in the print statement in updateUIView(). Any idea what could be wrong here? My goal is to have owner.geoJsonFeature not be nil.
0
0
366
Nov ’22
"Invalid top-level type in JSON write"
I have seen posts about this error message but i am making a new one because my case is different. the json is valid. so i have no clue why it gives out this error. Sample json here i removed the forward slash so it will be clean since when i do a print() it always shows as "key": "value" this is the code i use to convert it to data then it gives out that error. i checked the json in online json validator sites and it's good. let string = the json string from the url above let jsonObject = try? JSONSerialization.data(withJSONObject: string, options: []) It is supposed to be a json array. any idea why the error?
2
0
2.1k
Nov ’22
Why is this URL nil?
I am testing this in playground. I have no clue why this url does not work? nil is returned. print(URL(string: "http://202.90.159.177/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=Boundary:Boundary_Province&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG:3857&STYLES&BBOX=%f,%f,%f,%f")) The cause is &BBOX=%f,%f,%f,%f but i do not understand why that full url doesnt work if that is included. Going to use this in GMSURLTileLayer in ios maps utils.
1
0
509
Nov ’22