UIView addsubview after orientation change: Tell view to resize

后端 未结 4 2143
别那么骄傲
别那么骄傲 2021-01-05 09:08

I have a UIView as a XIB in Portrait mode.

This view is added programmatically to the viewcontroller like this:

NSArray *nibObjects = [[NSBundle main         


        
4条回答
  •  星月不相逢
    2021-01-05 10:13

    I don't know if you still have this issue.

    Let's say you have the following architecture:

    • window
      • subviewcontroller

    (you implemented shouldautorotate correct to answering the wanted orientations)

    Into this subviewcontroller you want to add the views of new UIViewControllers by just calling the addSubview function.

    Instead of implementing the bounds manipulation in shouldautorotate, you should implement it in

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
      self.newUIViewController.view.frame = self.view.bounds;
    }
    

    didRotateFromInterface... is called after shouldRotate. In this function the bounds are already setup correctly.

    This way you don't need so much manipulation by code.

提交回复
热议问题