XCode starts loading non-retina on retina display - ios

Somehow XCode starts partially draw non-retina images on both retina iPhone and Simulator. You can see image with standard searchbar below, it is even not my graphics, but as you can see magnifier is pixelated, while text is retina. Some of both my and system graphics are still retina, some not. I'm trying to clean project and restart XCode.

Turns out it's because I initialized my ViewController before application: didFinishLaunchingWithOptions:
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
let viewController = UITableViewController()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// add viewController to view hierarchy
}
}

Related

overrideUserInterfaceStyle not working in AppDelegate

I'm building an iOS app with the newest version of Xcode.
If I set
overrideUserInterfaceStyle = .light
to a View Controller, it will get set to light mode, also if dark mode is enabled.
But If I put this code in AppDelegate like this:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window?.overrideUserInterfaceStyle = .light
return true
}
it doesn't work.
There are no errors. The app simply is in light mode or dark mode depending on the mode the device is in.
Why doesn't overrideUserInterfaceStyle work in AppDelegate? Is it because I'm using a Tab Bar Controller for my app? I don't think so.
It's too early to call overrideUserInterfaceStyle in AppDelegate, window is not yet created. You can use SceneDelegate willConnectTo function.

Initial screen on iOS simulator is black

I have UIViewController that i created programmatically. This is the code. Even after setting my SignUpViewController background to white. I am getting black screen on launch
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
startWindowLoad()
return true
}
//extension with the starter function
extension AppDelegate {
func startWindowLoad () {
let startView = SignUpViewController()
let navView = UINavigationController()
navView.pushViewController(startView, animated: true )
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = startView
}
}
In a modern app, the app delegate window is not used. You need to use the scene delegate window. Move all the code into the scene delegate.
This is probably because your app is starting with LaunchScreen
Goto Info.plist and
change Launch screen interface file base name to Main

Ios 13 screen brightness problem by swift

I'm working on a project, and I have to control the screen brightness.
I use this to control:
UIScreen.main.brightness = CGFloat(0.80)
But, once I lock the screen and unlock, the screen brightness will change back to the system brightness, which could not go back to the brightness which I set before.
If there is any func I can use to change the screen brightness when users unlock the screen?
Thank you!
There is a method called applicationWillEnterForeground in UIApplicationDelegate which already conforms to your AppDelegate class.
Implement applicationWillEnterForeground by typing name of this method inside your AppDelegate class. like:
you can set the brightness whenever app goes to foreground
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
func applicationWillEnterForeground(_ application: UIApplication) {
UIScreen.main.brightness = CGFloat(0.80)
}
}

UIWindow results in a black screen when changing the rootViewController

I'll start with the main problem: My issue is not easily reproducible.
So... In my app, depending on whether it's the first time the user opens it, I am changing the rootViewController.
I do so like this:
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if /* code to figure out if it's the first launch */ {
let storyboard = UIStoryboard(name: "Onboarding", bundle: nil)
let onboardingViewController = storyboard.instantiateInitialViewController()
window?.rootViewController = onboardingViewController
}
return true
}
}
And this basically works great! As I am currently building that Onboarding ViewController, I removed the if and therefore it always get's displayed. This also worked fine, but all of a sudden the app would not start any more. The screen stays black. I then run the exact same code on an other device and it's working there.
Btw. the code above is all there is in my AppDelegate and the issues persists if the OnboardingVC has everything commented out.
When looking at the UI-Debugger for my app it also looks strange:
Normally there would be an arrow next to the UIWindow showing that it's root is indeed my VC, but in my case that's not the case.
I wouldn't mind and just delete the app from my device and reinstall it afterwards, but I've had one user-complaint for an other app of mine which users the same logic, who told me about the exact problem. Now I basically reproduced the issue but have no idea on where the problem should be.
My app is using storyboards btw.
Maybe somebody had that problem before and has any idea on what might be the problem.
EDIT:
Just had the problem again today... Here are some more observations:
When I initiate my ViewController and output it's view, it's not correct. It's not the view that is really set in the storyboard. It's a random other view.
Is it possible, that the storyboard is corrupt? And if so... what can I do about it?
After I added a random subview to my Main-View-Controllers view and run again, it worked again... So obviously the storyboard somehow got corrupt?
Ok... while development... ok... but for an app that's out there and all of a sudden the storyboard get's corrupt... that is really bad!!!!
Did anybody have that problem before? And how to solve it?
try this
in your case window is nil so
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
if /* code to figure out if it's the first launch */ {
let storyboard = UIStoryboard(name: "Onboarding", bundle: nil)
let onboardingViewController = storyboard.instantiateInitialViewController()
window?.rootViewController = onboardingViewController
}
return true
}
}
I've finally figured out the problem. For whatever reason I obviously double-linked the view outlet of my Initial-View-Controller to a subview. So it had two outlets to the view property (how is that even possible?)
And it randomly picked on or the other on startup....
Took a very sharp eye of a friend to see the problem :)

Instantiate UINavigationController in AppDelegate

I'm trying to instantiate a UINavigationController with a rootViewController in my AppDelegate. I've looked on this website, but all the examples were from Objective-C or used storyboards (which I'm trying to get away from). 'HomeScreenController` is the root view of the application.
Edit: this shows up in the console
2015-07-18 14:42:25.376 FastFactsSwift[4749:343495] Failed to instantiate the default view controller for UIMainStoryboardFile 'Main'
- perhaps the designated entry point is not set?
How do I fix this?
The following code results in just a black screen:
AppDelegate.swift:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window?.rootViewController = UINavigationController(rootViewController: HomeScreenController())
return true
}
...
HomeScreenController.swift:
import UIKit
class HomeScreenController: UIViewController, UISearchBarDelegate, UITableViewDelegate{
override func viewDidLoad(){
super.viewDidLoad()
var width = self.view.viewWidth
var height = self.view.viewHeight
//Add stuff to the view
}
...
Why is HomeScreenController showing up as a black screen?
The problem was not configuring AppDelegate to not use a storyboard.
How do I create a new Swift project without using Storyboards?

Resources