具有单个 uiview 控制器和多个视图的自动布局 iOS



我正在开发一个应用程序,该应用程序使用具有多个UIViews的几个UIView控制器。我正在尝试设置自动布局,但 UIViews 没有缩放到 UIView 控制器大小。有人可以指出一种解决此问题的方法,而无需重新设计应用程序架构吗?

所以我有一个UIView

控制器和一个子视图UIView(addNoteUIView(

当我将子视图添加到视图控制器时 子视图 添加注释 视图未通过自动布局调整大小到屏幕边界,它会被裁剪。

子视图不会调整为设备边界的大小

如何修复第二个UIView(添加注释视图(以遵循设备的边界?

编辑

谢谢维沙尔

我正在设置框架

加载
[self.collectionView setFrame:self.view.frame];
[self.collectionView setNeedsLayout];

但是,我从细胞中得到了这种行为。为什么会这样?多重边界? 查看带有集合视图单元格错误的图像

集合项大小的我的代码

- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGRect screenRect = [_collectionView bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat cellWidth = (screenWidth / (_lcolumns)); //Replace the divisor with the column count requirement. Make sure to have it in float.
CGFloat cellHeight = (screenHeight / (_lrows));
if(cellWidth < cellHeight)
return  CGSizeMake(cellWidth, cellWidth);
else
return  CGSizeMake(cellHeight, cellHeight);
}

它不是使用自动布局调整大小,您需要设置框架或需要以编程方式给出约束。

最新更新