UIView Not Resizing to fill iPhone 6 Window

2019-08-25 07:48发布

问题:

I have a UITableView in my .xib file. I have this password protected, by obscuring it with another UIView that has a UITextField. Once the password has been entered, I remove the UIView from the superview. However, I am running into an issue that the UIView is not covering up all of the UITableView on the 6 and 6 Plus. How can I go about doing this, given that the UIView is not the main view in the xib, and simply added? I use auto layout and told it to pin to leading and trailing, but it isn't working.

回答1:

I finally managed to solve this on my own. I already had told it to pin everything, so that rendered @NRitH answer as useless. I simply added

    [password setFrame:self.navigationController.view.bounds];

before adding the view as a subview, and it worked perfectly.



回答2:

You also need to pin its top and bottom edges. If it's in the same view that contains the stuff that you want to obscure, then pin the edges to the edges of the obscured content. Really, though, the comment about using a modal dialog is spot on.