Post

Replies

Boosts

Views

Activity

keyWindow?.bounds.size is nil at first load: Swift iPadOS 13
I am developing an app for iPad for iPadOS 13.There are two UICollectionViewController one navigates from one cell to another UICollectionViewController. I am using the following code:I have declared keyWindow at UICollectionView Controller as:let keyWindow = UIApplication.shared.connectedScenes .filter({$0.activationState == .foregroundActive}) .map({$0 as? UIWindowScene}) .compactMap({$0}) .first?.windows .filter({$0.isKeyWindow}).firstBut on first UICollectionViewController 'keyWindow?.bounds.size' gets printed as nil but on second UICollectionViewController same iPad Simulator 'keyWindow?.bounds.size' it gets printed as 'Optional((768.0, 1024.0))'. I am using the exact same code everywhere.func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { var sizeArea = CGSize() print("UIScreen.main.bounds.size \(UIScreen.main.bounds.size)") print(keyWindow?.bounds.size) if UIScreen.main.bounds.size == keyWindow?.bounds.size { print("UIScreen.main.bounds.size == keyWindow?.bounds.size") let spacing = self.view.frame.size.width - 25 let itemWidth = spacing / 4 sizeArea = CGSize(width: itemWidth, height: itemWidth) } else { print("else") let spacing = self.view.frame.size.width - 20 let itemWidth = spacing / 3 sizeArea = CGSize(width: itemWidth, height: itemWidth) } }What I am doing wrong here?
4
0
1.8k
Apr ’20
Reset macOS Catalyst Window Size to Default Minimum Size at Every Launch
I am using following code to have a minimum size for my app, It looks something like this:#if targetEnvironment(macCatalyst) func addWindowSizeHandlerForMacOS() { UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.forEach { windowScene in print("addWindowSizeHandlerForMacOS()") windowScene.sizeRestrictions?.minimumSize = CGSize(width: 800, height: 800) // windowScene.sizeRestrictions?.maximumSize = CGSize(width: 801, height: 1101) } } #endifI want to have same minimum size as the default size for every time my mac catalyst apps opens.Every instance my app relaunch it should open in its minimum size width and height i.e. 800 by 800.
2
0
1.9k
May ’20
StatusBarStyle suddenly not working in iOS / iPadOS 13, UINavigationBarController with Large Titles
I am using the following code to set the light colour for StatusBarStyle: But this code has suddenly stopped working in iOS 13 and iPadOS 13extension UINavigationController { override open var preferredStatusBarStyle: UIStatusBarStyle { get { return .lightContent } } }I have implemented UINavigationBarController with Large Titles for iOS 13 and iPadOS 13. I am using Xcode 11.4.1
1
0
1.1k
May ’20
Rearrange collection view cells within it's section
I have used UICollectionView Cells for my app. It is populated by Arrays. I have two CollectionView Sections. Section '0' & Section '1' has it's own cells populated with arrays. There are multiple cells in section 1. I want to enable user to rearrange cells within section 1. User should not be able to move cell from section 1 to section 0. I am using following code but It is giving me errors... I tried searching on the web but I didn't got the answer so I am posting it here for help... override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { let sourceSection = sourceIndexPath.section let destSection = destinationIndexPath.section if (sourceSection destSection) { let tempInputDataArray = inputDataArray.remove(at: sourceIndexPath.item) inputDataArray.insert(tempInputDataArray, at: destinationIndexPath.item) UserDefaults.standard.set(inputDataArray, forKey: "KeyForInputDataArray") for element in inputDataArray { print(element) } } else { } }
7
0
1.9k
Apr ’21
Refreshing / Reloading Data of Supplementary View (Header & Footer) for Collection View
I have deployed 2 Supplementary Views for Header and Footer views for my collection view. Header '0' has UILabel text which dynamically sets data dynamically after transitioning to push secondary view controller. But I am having problem that when UILabel in header loads again after returning and taking data from secondary view controller collection view get updated but Header and Footer Supplementary views has overlapping of old and new data...!!! How to fix overlapping of data and 'Reload Supplementary Views' for Header and Footer?
3
1
3.5k
Apr ’21
Implementing Free Trials for My Paid App
I have few questions about implementing free trials for my UIKit Swift App. Currently my app is paid i.e. One time purchase. I have good amount of user who have purchased my app as an Paid app previously. Now I want to introduce Trial period for my app I am also exploring RevenueCat framework for this... My Questions: If I implement Trial period then can I offer free app as my previous user have already bought my app when it was paid. And new user can use my app for free for 14 days then one time payment will start. Is there any good documentation for this kind of logic / programming? with source code examples... Thanks in advance...
0
0
918
Apr ’21
Changing UITabBar item image on selected and unselected state for Three Tabs but getting error
I have implemented three tab bar view controllers for my app. Each tab has collection views, And I have implemented following code in my ViewController to change tab bar image icon from stroke to fill on respective tab bar selection. I am using System Icons (SF Symbols). My Code: self.tabBarController?.tabBar.items?[0] = UITabBarItem(title: "Myanmar", image: UIImage(systemName: "m.square.fill"), selectedImage: UIImage(systemName: "m.square")) self.tabBarController?.tabBar.items?[1] = UITabBarItem(title: "Singapore", image: UIImage(systemName: "s.square"), selectedImage: UIImage(systemName: "s.square.fill")) self.tabBarController?.tabBar.items?[2] = UITabBarItem(title: "Hyderabad", image: UIImage(systemName: "h.square"), selectedImage: UIImage(systemName: "h.square.fill")) Error that I am getting at AppDelegate is: "Directly modifying a tab bar managed by a tab bar controller is not allowed." How to solve this?
4
0
8.4k
Apr ’21
Disable Dark Mode for iOS, iPadOS and macOS Catalyst App using Swift Programming Language
I want to disable Dark Mode system wide. Apple Developer has mentioned that you can add 'UIUserInterfaceStyle' key to info.plist. But I checked there is no such key in list and it also gives error when you upload app to the App Store. I tried using below code in AppDelegate.swift file. window?.overrideUserInterfaceStyle = .light' But it seems above code doesn't apply to LaunchScreen.storyboard How to fix this? That is LaunchScreen should also obey command to disable dark mode system wide.
6
0
4.3k
May ’21