Reputation: 619
I just started contributing to an iOS project and noticed this recurring pattern:
// This takes place in the superview
// This is the first access of subviewController.view,
// so the subview controller will create its view
// Then we'll immediately resize it to our desired frame
subviewController.view.frame = CGMakeRect(x, y, width, height);
It seems odd/inefficient to me for the subview's controller to create the subview with a particular frame size only to have the superview immediately resize it.
Is there some other design pattern I'm missing that allows the superview to pass the desired size to the subview from the get-go, so this immediate resizing is unnecessary?
Obviously the subview controller could just have a special method on it that takes the size as a param, but I'm wondering if this is a kosher/common pattern or not.
Upvotes: 0
Views: 305
Reputation: 11452
Where ever the subview is getting created, instead of creating with init
method you can always create with initWithFrame
. Btw, are we talking about a controller's main view? Then you can always set the view size from interface builder before compiling the project.
However, if the application needs the subview dynamically changed at every launch then the current way of doing it is the only option.
Upvotes: 1