我使用 UICOllectionView 制作水平滚动条。所有项目都使用cellForItemAtIndexPath
添加到集合视图中。但是在运行时我只能滚动到读取项目,该项目是最后一个,最后三个项目正在显示但无法滚动他们。任何想法如何解决这个问题?
在viewDidAppear
我有:
self.smilyObject =[[NSMutableArray alloc]initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"None",@"title", self.profilePic ,@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Happy",@"title",[[UIImage imageNamed:@"happyL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"In Love",@"title",[[UIImage imageNamed:@"inloveL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Confused",@"title",[[UIImage imageNamed:@"confusedL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Sad",@"title",[[UIImage imageNamed:@"sadL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Beauty",@"title",[[UIImage imageNamed:@"beautyL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Surprised",@"title",[[UIImage imageNamed:@"surpriseL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Angry",@"title",[[UIImage imageNamed:@"angryL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Sleepy",@"title",[[UIImage imageNamed:@"sleepyL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Love",@"title",[[UIImage imageNamed:@"loveL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Hangover",@"title",[[UIImage imageNamed:@"hangoverL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Driving",@"title",[[UIImage imageNamed:@"drivingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Chilling",@"title",[[UIImage imageNamed:@"chillingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Eating",@"title",[[UIImage imageNamed:@"eatingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Workout",@"title",[[UIImage imageNamed:@"workoutL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Movie",@"title",[[UIImage imageNamed:@"movieL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Insomnia",@"title",[[UIImage imageNamed:@"insomiaL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Boozing",@"title",[[UIImage imageNamed:@"boozingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Coding",@"title",[[UIImage imageNamed:@"codingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Coffee",@"title",[[UIImage imageNamed:@"coffeeL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Music",@"title",[[UIImage imageNamed:@"musicL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Cooking",@"title",[[UIImage imageNamed:@"cookingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Gaming",@"title",[[UIImage imageNamed:@"GamingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Late",@"title",[[UIImage imageNamed:@"lateL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Making",@"title",[[UIImage imageNamed:@"makingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Middle",@"title",[[UIImage imageNamed:@"middleL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Read",@"title",[[UIImage imageNamed:@"readL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Shopping",@"title",[[UIImage imageNamed:@"ShoppingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Singing",@"title",[[UIImage imageNamed:@"singingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Smoking",@"title",[[UIImage imageNamed:@"smokingL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Stuck In Traffic",@"title",[[UIImage imageNamed:@"trafficL.png"] scaleToSize:CGSizeMake(40.0, 40.0)],@"image", nil],
nil];
[self.collectionData reloadData];
我还补充说:
#pragma mark Collection view layout things
// Layout: Set cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"SETTING SIZE FOR ITEM AT INDEX %ld", (long)indexPath.row);
CGSize mElementSize = CGSizeMake(70, 70);
return mElementSize;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 2.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 2.0;
}
// Layout: Set Edges
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
// return UIEdgeInsetsMake(0,8,0,8); // top, left, bottom, right
return UIEdgeInsetsMake(0,0,0,0); // top, left, bottom, right
}