Top IOS Interview Questions and Answers (Sept 2018) Part 3
Top IOS Interview Questions and Answers (Sept 2018) Part 3
iOS interview questions 2018
Q1. You have a iOS app which is in foreground, User press Home button on iPhone, Which API’s of UIViewController will be called, describe in correct sequence?
Solution: ViewWillDisappear -> ViewDidDisappear
There are three ways to load a viewcontroller -
-
To load a view controller from a storyboard, call the
instantiateViewController(withIdentifier:)
method of the appropriateUIStoryboard
object. -
To initialize a view controller object using a nib file,
create your view controller class programmatically and
initialize it using the
init(nibName:bundle:)
method. -
Specify the views for a view controller using the
loadView()
method. In that method, create your view hierarchy programmatically and assign the root view of that hierarchy to the view controller’sview
property.
Q2. What is intrinsic content size?
Solution: Views having their natural size based on content size, is referred to as their intrinsic content size. For example, a button’s intrinsic content size is the size of its title plus a small margin.
Q3. What is content hugging, compression resistance, can you tell default values for a view?
Solution: Auto Layout represents a view’s intrinsic content size using a pair of constraints for each dimension. The content hugging pulls the view inward so that it fits snugly around the content. The compression resistance pushes the view outward so that it does not clip the content.
Each of these constraints can have its own priority. By default, views use a 250 priority for their content hugging, and a 750 priority for their compression resistance. Therefore, it’s easier to stretch a view than it is to shrink it.
Q4. Consider this scenario: Consider a Image detail page in an application, positioned relative to superview. But on iPhone X, Even though this particular view uses Auto Layout, the page control is too far down at the bottom of the screen. It’s running into the Home indicator. How will you solve this problem?
Solution: The problem here is that the page control’s bottom constraint is relative to the superview, which is full screen and goes behind the Home indicator. Instead of constraining to the superview, what we should do is constrain the page control to the Safe Area layout guide at the bottom. Instead of the Superview, if we change this to be connected to the Safe Area, then on iPhone X the page indicator will automatically move up above the Home indicator.
Q5. What is View auto layout life cycle?
Solution: There are 3 steps after initialization of UIView in auto layout cycle.
-
Update pass
(calculating view frame based on its constrains)
The system traverses view hierarchy top-down, i.e. from super- to subviews, and callsupdateConstraints()
for each view. -
Layout pass ( frames of each view are updated with the rectangles
calculated in the
Update phase.)
It happens bottom-up, i.e. the system traverses views from sub- to superviewsand callslayoutSubviews
for each. -
Render pass
(responsible for bringing pixels onto the screen)
The key method here isdrawRect
.By default,UIView
passes all the work to a backingCALayer
that contains a pixel bitmap of the current view state. This step is independent of whether Auto Layout is enabled for a view or not.
References:
- https://developer.apple.com/documentation/uikit/uiviewcontroller
- https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#//apple_ref/doc/uid/TP40010853-CH9-SW1
- https://developer.apple.com/videos/play/tech-talks/201
- http://www.vadimbulavin.com/view-auto-layout-life-cycle/