When to use a UIView vs. a UIViewController on the iPhone?

前端 未结 9 764
谎友^
谎友^ 2020-12-04 16:25

I have always sort of wondered when to use a UIView vs. a UIViewController on the iPhone.

I understand that you shouldn\'t use a UIViewController unless it\'s a full

9条回答
  •  孤城傲影
    2020-12-04 17:09

    A UIView is part of the UIViewController see the view property of UIViewController for this. As you pointed out correctly UIViewController manages a complete screen and there should be only one visible UIViewController at a time. But in most cases you will have more UIViews or subclasses of UIView visible on the screen.

    The example you gave would be a correct use in most cases. As you may have noticed you will get a lot of functionality when subclassing the UIViewController. Animating the appearance and dismissal of the UIViewController would be one of them.

    As marcc pointed out if the thing you want to slide in is not a self contained screen you would be better off using a UIView.

    As a conclusion I would say that if you want to use the functionality that comes with subclassing UIViewController than go for it make it a UIViewController. Otherwise a UIView might be better.

    The itunes U Standford class has a great lecture on UIViewControllers I would recommend watching it, because it has a lot of information regarding UIViewControllers in general.

提交回复
热议问题