What is the relationship between Storyboard form factor & Active Scheme in Xcode using Autolayout?

白昼怎懂夜的黑 提交于 2019-12-05 17:32:59

No, Storyboard form factor is there to show you what it looks like in different screen sizes. It does not dictate the size of the views in runtime.

My guess is that there must be some constraint in your view that is not set up correctly to work with 4" screen in that screen.

I know this question is old, but I just experienced and solved the same problem.

My situation was this:

1) I have a UITableView, constrained to the size of my view controller's frame. 2) In viewDidLoad method I added a table header view to it, using the frame of my table view as the header's frame.

UIView *headerView = [UIView alloc]initWithFrame:self.tableView.frame];    
self.tableView.tableHeaderView = headerView;

This gave me a header that hid the contents on the table view until the header was swiped up (similar to Yahoo weather).

3) At the bottom of the header I had a couple labels displaying information that would be visible before the upward swipe.

The problem:

If I launched my app on the 3.5" emulator BUT had the storyboard set to the 4" phone the labels at the bottom of my header view would render below the bottom of the screen, cutting them off.

If I launched my app on the 4" emulator BUT had the storyboard set to 3.5", the labels appeared too high in the table's header view.

If I launched the app on the same size emulator as the storyboard was set to, everything worked perfectly.

After hours of head banging, I realized that my table view's frame was not set using the auto layout constraints when viewDidLoad is called. It was inferring the size from my storyboard at that point, and adjusting based on the constraints later. As a result, my table view header was not the same size as my table view as expected.

Moving the code adding the table view header, based on the size of the table view to the

viewDidLayoutSubviews 

method, when the auto layout constraints had been applied solved the problem.

I had the same issue with a UIScrollView. The answer above from user3847320 is probably correct. But in my case I got a crash while doing the layout stuff in viewDidLayoutSubviews.

To quickly avoid this, just add the following in the viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scrollView.frame = self.view.frame;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!