UIKit is a framework that was introduced by Apple in 2007 alongside the original iPhone. Today, UIKit remains a crucial part of the iOS development toolkit and is used by developers worldwide. As such, knowledge of UIKit is an essential skill for any iOS developer and is likely to be a topic of discussion in any iOS-related interview.
To prepare for iOS interview questions related to UIKit, refresh your knowledge and be familiar with following topics:
UIKit is a framework that enables you to build user interfaces (UI) for iOS, iPadOS, or tvOS apps. It provides the window and view architecture for implementing your UI, the event-handling infrastructure for delivering Multi-Touch and other types of input to your app, and the main run loop for managing interactions between the user, the system, and your app.
UIKit also includes support for animations, documents, drawing and printing, text management and display, search, app extensions, resource management, and getting information about the current device.
The responder chain is a series of linked responder objects that handle events in iOS apps. A responder object is any instance of the UIResponder class, such as views, view controllers, or the application object. Events are types of input that occur in your app, such as touch events, press events, shake-motion events, remote-control events, or editing menu messages.
When your app receives an event, UIKit automatically directs that event to the most appropriate responder object, known as the first responder. The first responder varies depending on the type of event. For example, for touch events, the first responder is the view in which the touch occurred; for press events, the first responder is the object that has focus; for editing menu messages, the first responder is the object that you designate.
UIKit manages the responder chain dynamically, using predefined rules to determine which object should be next to receive an event. For example, a view forwards events to its superview, and the root view of a hierarchy forwards events to its view controller.
UIStackView is a control that leverages the power of Auto Layout and Size Classes to manage a stack of subviews, either horizontally or vertically, that dynamically responds to the device’s orientation and screen size.
The order of the subviews in the stack view is determined by their order in the arrangedSubviews array. The exact layout of the subviews depends on the stack view’s distribution, alignment, spacing, and other properties.
You can also fine-tune an arranged view’s appearance by adding additional constraints to the arranged view. For example, you can use constraints to set a minimum or maximum height or width for the view. Or you can define an aspect ratio for the view. Be careful to avoid introducing conflicts when adding constraints to views inside a stack view.
To handle keyboard appearance and disappearance in a view controller, you need to do the following steps:
deinit
method of your view controller to remove the observers for the keyboard notifications.