Orientation Problem while using insertSubview

霸气de小男生 提交于 2019-11-29 13:08:52

UIWindow has a subview that it uses for rotations and puts other views inside of that. You need to insert yourself into the root view (or something lower), not the window. Look at -[UIWindow rootViewController].

UIView *rootView = [[[self window] rootViewController] view];
[rootView addSubview:view];

This will work as long as you're using something with a root view controller. This will work as long as rootViewController isn't nil. If you're doing a raw "View Based" application, then it's usually best to pick another view and add your view as its sibling rather than digging through the undocumented hierarchy:

UIView *sibling = ... (some other view)
[[sibling superview] addSubview:view];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!