开发者

Difference between a UIViewController's view frame and navigationController.view.frame?

开发者 https://www.devze.com 2023-02-09 08:30 出处:网络
I have a UIViewController derived class that is part of a UINavigationController\'s view controller. There\'s the view that\'s part of the UIViewController and there\'s also access to navigationContr

I have a UIViewController derived class that is part of a UINavigationController's view controller.

There's the view that's part of the UIViewController and there's also access to navigationController property.

So what's the d开发者_开发百科ifference between

self.navigationController.view.frame 

vs

self.view.frame

in terms of the UIViewController class?


navigationController is just a convenient property on UIViewController that gives you access to a view controller's containing navigation controller, should it have one. Since UINavigationController extends UIViewController, it, too, has a view property. See the documentation for Getting Other Related View Controllers in UIViewController's class reference for a list of other view controller references UIViewController can potentially have.

  • self.navigationController.view.frame gives you the frame of the navigation controller's view
  • self.view.frame gives you the frame of the view controller's view

A navigation controller's view frame is larger than any of its container view controllers' view frames because it includes the navigation bar and the status bar.

Hope this helps clear things up a bit!


I'm not sure I understand the relationship of your view controllers, but in general view.frame returns a CGRect with coordinates (origin (x,y) and size(width,hieght)) relative to the views superview. So, if your navigationController is the parent view of your derived UIViewController, then calling 'self.view.frame' in that controller will return coordinates relative to the navigationController. Calling self.navigationController.view.frame will return its coordinates relative to its superview, whatever that might be.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号