【发布时间】:2013-08-21 12:59:39
【问题描述】:
我在界面构建器中创建了一个 UICollectionView。我用
引用了它@property (strong, nonatomic) IBOutlet UICollectionView *contactList;
在我的 .h 文件和 @synthesize 联系人列表中;在我的 .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 它仍然没有更新。
-
您是否尝试过使用 spring-struts/autolayout 自动设置大小?
-
@AnuragSoni 我对我的应用程序中的几乎所有东西都使用了自动布局,但我无法让它适合我的 collectionview 的大小,因为它不应该真正“捕捉”到任何东西或成为距离边缘一定距离。
-
@AnuragSoni 我设法让自动布局来做我想做的事。我认为这足以让我继续前进,谢谢。
标签: ios objective-c uicollectionview