0
我正在使用水平自動滾動使用計時器。我想讓它一個一個滾動。UICollectionView - 水平自動滾動與計時器
就我而言,它是從左向右滾動連續。最後它還會在最後一個單元格之後滾動空白區域。
@interface AccountsVC()<UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
CGFloat width_Cell;
NSTimer *autoScrollTimer;
}
- (void)viewDidLoad
{
[super viewDidLoad];
width_Cell = 0.0;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self configAutoscrollTimer];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self deconfigAutoscrollTimer];
}
- (void)configAutoscrollTimer
{
autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
- (void)deconfigAutoscrollTimer
{
[autoScrollTimer invalidate];
autoScrollTimer = nil;
}
- (void)onTimer
{
[self autoScrollView];
}
- (void)autoScrollView
{
CGPoint initailPoint = CGPointMake(width_Cell, 0);
if (CGPointEqualToPoint(initailPoint, self.collectionView.contentOffset))
{
if (width_Cell < self.collectionView.contentSize.width)
{
width_Cell += 0.5;
}else
{
width_Cell = -self.view.frame.size.width;
}
CGPoint offsetPoint = CGPointMake(width_Cell, 0);
self.collectionView.contentOffset = offsetPoint;
}else
{
width_Cell = self.collectionView.contentOffset.x;
}
}
您的CollectionView細胞寬度等於您self.width ???或者是你先顯示3個單元然後滾動3個單元格? –
@AgentChocks。沒有全部基於數組數。滾動從數組中的第一個元素開始直到結束,然後反轉 – ChenSmile
@AgentChocks。你有任何解決方案 – ChenSmile