Post

Replies

Boosts

Views

Activity

Reply to Why is superview returning nil?
See the Apple document excerpt below. If calling animation didMove(toParent:) is called after the transition not inside of the animation block, no animation the immediately after the addChild. With animation @objc func buttonAction(sender: UIButton!) { guard let theButton = sender as? MyButton else { return} UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in self.addChild(setController) self.view.addSubview(setController.view) }, completion: { setController.didMove(toParent: self) }) } No animation @objc func buttonAction(sender: UIButton!) { guard let theButton = sender as? MyButton else { return} self.view.addSubview(setController.view) self.addChild(setController) setController.didMove(toParent: self) } Discussion Your view controller can override this method when it wants to react to being added to a container. If you are implementing your own container view controller, it must call the didMove(toParent:) method of the child view controller after the transition to the new controller is complete or, if there is no transition, immediately after calling the addChild(_:) method. The removeFromParent() method automatically calls the didMove(toParent:) method of the child view controller after it removes the child. Sundel: https://www.swiftbysundell.com/basics/child-view-controllers/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to Taking user input in MapKit
Your solution can be the extra work. Google, search GitHub or reach the Apple Documentation, look at the sample code. Begin the base knowledge here: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW1 Converting MKView touch to coordinates: https://gist.github.com/a1phanumeric/2249553
Dec ’21
Reply to How to know the active & foreground scene in multi-windows supported iPadOS app?
Traverse the scene hierarchy for an active or main window something like below. Might need tweaking. extension UIWindow { public static var keyWindow: UIWindow ? { if #available(iOS 13.0, *) { return UIApplication.shared.connectedScenes .compactMap { $0 as? UIWindowScene } .first?.windows.filter { $0.isKeyWindow }.first } else { return UIApplication.shared.keyWindow } } }
Topic: App & System Services SubTopic: Hardware Tags:
Nov ’21
Reply to iOS15 NavigationView lost the state after putting app in background and bring it back
Move the parent NavigationView from LocalNotificationDemoView to the MainView tabs. There is no need for the .navigationViewStyle(.stack) modifier. struct LocalNotificationDemoView: View {     var body: some View {         VStack {             MainView()         }     } } struct MainView: View {     var body: some View {         TabView {             NavigationView {                 Tab1()             } .tabItem {                 Text("Tab1")             }             NavigationView {                 Tab2()             }.tabItem {                 Text("Tab2")             }         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21