Orientation Problem while using insertSubview

后端 未结 1 970
野的像风
野的像风 2020-12-20 09:45

I get an orientation problem while using the following to code to display a view on top of a split view.

[window addSubview:aSplitViewController.view];
[wind         


        
相关标签:
1条回答
  • 2020-12-20 10:47

    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];
    
    0 讨论(0)
提交回复
热议问题