iOS UIView - kgleong/software-engineering GitHub Wiki
UIView
Positiong properties
CGRect
- A struct containing the following sub structs:
- Origin - A
CGPoint
representing the top left corner of a frame or bounds. - Size - A
CGSize
struct representing the width and length.
- Origin - A
Frame Describes the minimal bounding box for the view with respect to the parent view's coordinate system. This also takes into account any transformations (e.g., rotation, scaling) that have been applied.
This is a computed property.
Calculated using the bounds
, position
, and transform
.
Changing the frame may also update these dependent properties as well.
According to Apple's documentation on the frame property, be wary of the view.frame
property when transforms are applied.
If transformations may be applied to a view, then it's better to reference the center and bounds when repositioning the view.
This is because the frame
property is undefined after a non-identity transformation is applied.
Bounds
Center
A CGPoint
that represents the center of view with respect to the parent's coordinate system.
References
- How to center a subview - StackOverflow
- Understanding UIScrollView and Bounds - Oleb.net
- You Probably don't understand frames and bounds - Ash Furrow
- Core Animation - Google books
- Whats the different between frame and bounds - StackOverflow
Initializers
References
Lifecyle
Callback | Trigger |
---|---|
init(frame:) |
|
init(coder:) |
|
willMoveToSuperview |
|
invalidateIntrinsicContentSize |
|
didMoveToSuperview |
The view has been added to a view hierarchy. self.superview is now populated. |
awakeFromNib |
|
willMoveToWindow |
|
needsUpdateConstraints |
|
didMoveToWindow |
|
layoutSubviews |
|
drawRect |
References
UIView
Custom Interface Builder References
Navigation Controller interactions
Extending the view under the navigation bar
var viewController = UIViewController()
// The top of the view will be under the status bar the navigation bar,
// if present.
viewController.edgesForExtendedLayout = UIRectEdge.None
// The root view fills the entire screen, including under the status bar and
// under a navigation bar if present.
viewController.edgesForExtendedLayout = UIRectEdge.All