【发布时间】:2016-03-16 12:30:11
【问题描述】:
我使用 iCarousel lib 作为我的应用程序的滚动视图。该库的目的是管理自动滚动图像。图像设置为 iCarousel 类的边界(实际上是UIView。最初加载时它工作正常,但是当我旋转设备时,它会输出奇怪的错误。例如,如果我从纵向滑动到横向,只需要几分之一秒我们可以看到以下内容:
出于某种原因,我们看到“旧”图片
这是我如何声明显示视图的主要方法:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
NewScrollerItemForIPad *item;
NewsItemMdl *mdl = self.viewModel.arrNews[index];
if(mdl){
/* Check for orientation */
BOOL _isPortrait;
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
_isPortrait = NO;
} else {
_isPortrait = YES;
}
if (self.gotNews){
if(!item){
item = [[NewScrollerItemForIPad alloc] initWithFrame:car.bounds andOrientation:_isPortrait];
}
[item bindViewModel:mdl];
}
}
return item;
}
以及自动滚动方式:
-(void)runMethod{
if(self.sliderCount== (self.pageControl.numberOfPages-1)){
NSLog(@"Here we call");
self.pageControl.currentPage = 0;
self.sliderCount = 0;
[car scrollToItemAtIndex:self.sliderCount animated:YES];
}else{
NSLog(@"And here we call");
self.sliderCount++;
self.pageControl.currentPage ++;
[car scrollToItemAtIndex:self.sliderCount animated:YES];
}
}
如何修复该错误?显然我不想在新图像之间加载未来和旧图像。
【问题讨论】:
-
我不确定它是
iCarousel中的feature 还是bug,但我可以告诉你它的实现和行为非常- 非常奇怪(主要是错误)——我们在方向改变后为解决问题所做的工作,我们每次都会在实际的iCarousel实例上调用–reloadData方法。 -
@holex 我确实打电话给 [car reloadData];在 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {,但不幸的是问题并没有消失。
-
如果您在实际轮换发生之前重新加载数据,这对您并没有真正的帮助;您需要在之后进行。
-
@holex 好的,我试试,谢谢!:)
-
@EvgeniyKleban 我对 iCarousel 也有同样的问题。当我在屏幕旋转后运行 reloadData 时,我可以在一秒钟内看到旧尺寸的轮播。它看起来不那么漂亮。你能告诉我你是怎么解决这个问题的吗?也许你应该添加你对这个问题的答案。
标签: ios objective-c icarousel