如何确定旋转木马的指标?或者数组的索引加载到其中?我已经从NSDocumentDirectory加载了我的图像。
self.myImages = [NSMutableArray new];
for(int i = 1; i <= 30; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]];
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
NSLog(@"file exists");
}
} 并将它们添加到iCarousel视图中:
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[myImages objectAtIndex:index]];
return view;
}发布于 2012-06-05 15:30:22
如果我没有误解您的问题,您可以尝试使用UIView的tag属性进行比较。例如:
在viewForItemAtIndex:中
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[myImages objectAtIndex:index]];
view.tag = index;
return view;
}将currentItemView与另一个图像进行比较
If (int == [(UIImageView*)[self.carousel currentItemView] tag]) {
//do something
}发布于 2012-06-05 14:23:36
(在代码中)哪里需要carousel的索引?当您将图像添加到旋转木马(在viewForItemAtIndex:中)时,以及当您轻拍旋转木马(在didSelectItemAtIndex:中)时,您就知道了。
此外,您还可以使用轮播的currentItemIndex属性。
https://stackoverflow.com/questions/10892465
复制相似问题