- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Nick Lockwood 的 iCarousel对于 iPad 应用程序。现在它只是 15 个全屏图像的轮播。
我设置了一个单 View 项目,在 Storyboard 中添加了 iCarousel View ,将它的 View Controller 添加为数据源并将此代码放入数据源方法中:
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return 15;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
UIImage* img = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.jpg", index]];
UIImageView* imgView = [[UIImageView alloc] initWithImage:img];
return imgView;
}
这行得通,但是当我第一次滚动浏览所有项目时,您会注意到在将新项目添加到轮播时性能受到了一点影响。当我第二次检查所有项目时,就不会发生这种情况。
您可以在这个分析器屏幕截图中明白我的意思。上半场的峰值是我第一次滚动浏览所有图像,然后我再次滚动,没有峰值,也没有性能下降。
我该如何解决这个问题?
编辑
我分离了仪器上的一个峰值,这是调用树
编辑
jcesar建议的代码
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray* urls_aux = [[NSMutableArray alloc] init];
for (int i = 0; i<15; i++) {
NSString *urlPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"captura%d", i] ofType:@"jpg"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
[urls_aux addObject:url];
}
self.urls = urls_aux.copy;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeLinear;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
if (view == nil) {
view = [[[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)] autorelease];
view.contentMode = UIViewContentModeScaleAspectFit;
}
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:view];
((AsyncImageView *)view).imageURL = [self.urls objectAtIndex:index];
return view;
}
最佳答案
我不认为这是一个非常正统的解决方案,但它确实有效。
我所做的是使用 iCarousel 的方法 insertItemAtIndex:animated:
在设置时一次添加一个图像。然后性能受到影响,但之后一切运行顺利。
- (void)viewDidLoad
{
[super viewDidLoad];
self.images = [[NSMutableArray alloc] init];
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeLinear;
for (int i = 0; i<15; i++) {
UIImage* img = [UIImage imageNamed:[NSString stringWithFormat:@"captura%d.jpg", i]];
[self.images addObject:img];
[self.carousel insertItemAtIndex:i animated:NO];
}
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return self.images.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
UIImage* img = [self.images objectAtIndex:index];
UIImageView* imgView = [[UIImageView alloc] initWithImage:img];
return imgView;
}
关于ios - iPad 上的 iCarousel 性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15831148/
我在我的应用程序中使用 iCarousel,我需要获取 iCarousel 的当前索引并将该索引显示在标签(self.view 的 subview )中,该标签不是 iCarousel 的 subvi
我正在使用 iCarousel 来滚动图像。代码是: - (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(
我使用 iCarousel 库在我的屏幕上滚动许多 UIView。每个 View 填满整个屏幕。 我需要以某种方式配置 iCarousel,以便通过短触仅滚动一个 View 。 我现在有 carous
我正在使用 iCarousel 滚动标签。在模拟器上一切正常,但在 iPad/iPhone 上滚动并不顺畅和快速 这是代码。 城市 ListView .h #import #import "iCar
我正在使用 iCarousel framework . https://github.com/nicklockwood/iCarousel 在那里我想找出 View 的滑动方向 ,因为我有下一个和上一
我正在使用NickLockwood的iCarousel。我不明白为什么不调用viewForItemAtIndex(设置断点且未命中)一切都已正确完成。datasource和delegate设置为sel
我想获取用户点击的索引。我尝试了多种方法来检测它,但都不起作用。这是我尝试过的。 func carousel(carousel: iCarousel, didSelectItemAtIndex
我正在尝试创建一个“上传图像”系统,并且我正在尝试调整每个图像之间的空间。然而,它并没有按计划进行,因为当轮播停止移动时,由于重叠,图像总是必须移到前面。我怎样才能阻止这种重叠?谢谢! func ca
我在 CollectionView 中使用 iCarousel 模块。轮播 View 位于我的 UICollectionViewCell 中。 我的代码如下。 class CelebrityDetai
我开始使用 iCarousel 但出现了这个错误: Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
我在我的应用程序中使用了很棒的 iCarousel 库。但我面临一个问题。我正在使用此代码将数据填充到轮播中。 - (NSUInteger)numberOfItemsInCarousel:(iCaro
如何确定轮播的索引?或者加载到其中的数组索引?我已经从 NSDocumentDirectory 加载了图像。 self.myImages = [NSMutableArray new]; for(in
我已经在我的应用程序中实现了 iCarousel。我想让 iCarousel 通过用户迭代仅向一个方向滚动。 我的场景是一个 View 列表,用户只能通过回答当前 View 上的问题来转到下一个 Vi
我有一个 iCarousel,它包含一些位于屏幕底部下方的元素(即它们可以滚动到)。 我正在执行一个动画,其中将 CGAffineTransformMakeScale 应用于该 UIScrollVie
所以我尝试使用 iCarousel 以图像形式显示产品,然后用户可以简单地滚动并查看所有可用的产品。 出于某种原因,当您加载 viewcontroller 时,它根本不显示任何图像,甚至不显示轮播,它
我已经以编程方式设置了按钮,如下所示:- -(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index r
我在我的 CoverFlow 应用中实现了 iCarousel。我找不到检测方法,现在显示的是哪个 View 。 有人知道吗?谢谢。 最佳答案 根据documentation ,您可以使用属性 cur
如何在特定项目或索引中滚动,例如:我在另一个 UIView 上设置了一个 NSInteger,然后将它传递给我的 iCarousel .在我的另一个 UIView 中,我这样设置 NSInteger:
我已经实现了 iCarousel 的这个方法, 开始时它会卡住,几秒钟后它允许我滚动。而且我不希望图像在滚动时重叠,我希望它们在每个项目之间都具有相等的距离。 这段代码有什么问题?或者我遗漏了什么?
我正在尝试使用以下代码将 iCarousel 添加到现有项目,但出现此错误:MemberCatalog[14990:1a903] -[MainViewController carousel:viewF
我是一名优秀的程序员,十分优秀!