我有一个 UICollectionView 显示一个垂直的单元格列表。它基本上是一个表格视图,但我使用集合视图来更好地控制每个单元格在视图中的放置方式。由于某种原因,集合视图中的最后一个单元格被剪裁了。我可以向上拖动以查看下半部分,但只要我放手,集合视图就会弹回原位,遮挡最后一个单元格的下半部分。我有一个包含集合视图的 xib,然后我从另一个 xib 注册集合视图单元格。整个视图以编程方式放置在导航控制器中。我的想法是它必须是自动布局的问题。由于我以编程方式将包含集合视图的视图控制器添加到导航控制器,因此在集合视图和导航栏之间没有设置任何约束。如果我隐藏实例化的导航栏并在 IB 中拖出一个,则不会剪切集合视图单元格。但我不想这样做。我已经尝试以编程方式添加约束,但这也不起作用。有没有人有什么建议?下面是我如何创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我尝试用于添加约束的代码是包含。目前,我在 didFinishLaunchingWithOptions 的应用程序委托中执行此操作:m 创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我尝试用于添加约束的代码是包含。目前,我在 didFinishLaunchingWithOptions 的应用程序委托中执行此操作:m 创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我尝试用于添加约束的代码是包含。目前,我在 didFinishLaunchingWithOptions 的应用程序委托中执行此操作:
self.homeViewController = [[FFHomeViewController alloc] init];
FFNavigationPanelViewController *navigationController = [[FFNavigationPanelViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
// frontNavigationController.navigationBarHidden = YES;
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:navigationController];
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.homeViewController.collectionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.homeViewController.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.viewController.frontViewController.view addConstraint:topConstraint];