我在界面构建器中创建了一个UICollectionView。我用以下代码引用它:
这段代码运行正常,但我还想改变页面大小(横屏时每页有2*3的网格,在竖屏时是3*2的网格)。我尝试像这样设置大小:
@property (strong, nonatomic) IBOutlet UICollectionView *contactList;
在我的.h文件中,使用@synthesize contactList; 在我的.m文件中。我试图使用以下代码在纵向和横向实现稍微不同的布局:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout*)contactList.collectionViewLayout;
flow.sectionInset = UIEdgeInsetsMake(48, 80, 48, 0);
flow.minimumLineSpacing = 80;
} else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout*)contactList.collectionViewLayout;
flow.sectionInset = UIEdgeInsetsMake(48, 64, 48, 0);
flow.minimumLineSpacing = 64;
}
}
这段代码运行正常,但我还想改变页面大小(横屏时每页有2*3的网格,在竖屏时是3*2的网格)。我尝试像这样设置大小:
CGRect frame = [contactList frame];
frame.size.width = 960;
[contactList setFrame:frame];
但是它没有更新。没有错误,但视图没有更新。它仍然保持与之前相同的大小。我需要做什么才能更新视图?
self.contactList
吗? - Amar