我有一个标签栏应用程序,开始标签包含一个几乎全屏的集合视图,其中包含分页图像。当应用程序打开时,分页不起作用是粗糙和零星的,但是,如果您更改选项卡然后返回到初始分页,则分页工作绝对正常。
有没有人经历过这个或者知道是什么导致了这个?
以下是使用的代码:
#import "HomeViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self createStoneData];
}
- (void)createStoneData {
self.homeImages = [NSMutableArray array];
[self.homeImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Biddlesdon Wardrobes", @"name",
@"_NP19981-Edit.jpg", @"image", nil]];
etc….etc…etc….
[self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.homeImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *homeImageView = (UIImageView *)[cell viewWithTag:100];
homeImageView.image = [UIImage imageNamed:[[self.homeImages objectAtIndex:indexPath.row] objectForKey:@"image"]];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (_startingIndexPath) {
NSInteger currentIndex = floor((scrollView.contentOffset.x - scrollView.bounds.size.width / 1) / scrollView.bounds.size.width) + 1;
if (currentIndex < [self.homeImages count]) {
self.title = self.homeImages[currentIndex][@"name"];
}
}
}
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.collectionView.collectionViewLayout invalidateLayout];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end