Where to determine UIView size

后端 未结 3 1579
暗喜
暗喜 2021-02-01 04:03

Summary: How should the UIViewController know the size of its UIView instance when initialising that view?

The dedicated initialisation method for an UIView

3条回答
  •  离开以前
    2021-02-01 04:32

    I'm currently trying to accomplish the same thing after subclassing from UIViewController to create a generic component and came to notice something quite weird :

    UIViewController has a "loadView" method that you may override to (quoting documentation) "This is where subclasses should create their custom view hierarchy".

    So, i create my view hierarchy, compositing my screen using a default frame size (since I may not be knowing the frame i should display things into at the time loadView is called).

    But then, upon what call do I correctly set frame sizes ? Aka : at what time is my view controller aware of it's view real size ?

    Do I have to create a "setFrame" in my ViewController subclass that the object creating the viewcontroller should call ? that seems weird.

    drvdijk : did you have a solution to your problem ?

    EDIT : just found this Note on UIViewController documentation : Note: You should not use view controllers to manage views that fill only a part of their window—that is, only part of the area defined by the application content rectangle. If you want to have an interface composed of several smaller views, embed them all in a single root view and manage that view with your view controller.

    So, it seems that UIViewController main view is always full screen. Period.

    That does pose a problem to me though, as I'm trying to create a custom UITabBarViewController (to be able to display custom images in the tabbar, and not blue gradient) : my tabBarViewController should displays subviewcontrollers into a part of the window only...

提交回复
热议问题