0

在这里坚持我已经将 iCarousel 的这种方法实现为,

它在开始时变得粘滞,几秒钟后它允许我滚动。而且我不希望图像在滚动时重叠,我希望它们在每个项目之间都具有相等的距离。

这段代码有什么问题?或者我错过了什么?

-(void)addiCarousel
{
    carousel.frame = CGRectMake(324, 50, 375, 195);
    [self.view addSubview:carousel];
    self.items = [[NSMutableArray alloc] initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg", nil];
    carousel.type = iCarouselTypeCoverFlow2;
    [carousel reloadData];
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [items count];
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return NO;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

 //   if (view == nil)
   // {
        view = [[[UIImageView alloc] initWithFrame:CGRectMake(649, 50, 375 , 195)] autorelease];
        view.contentMode = UIViewContentModeCenter;
        view.layer.borderWidth = 8.0f;
        view.layer.borderColor = [[UIColor blackColor] CGColor];
    view.contentMode = UIViewContentModeScaleToFill;

//    }

     ((UIImageView *)view).image = [UIImage imageNamed:[self.items objectAtIndex:index]];

    NSLog(@"index : %d",index);
    NSLog(@"%@",[self.items objectAtIndex:index]);

    return view;
}
4

3 回答 3

2

你用过下面的方法吗

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
//usually this should be slightly wider than the item views
return 240;
}

此信息在教程中给出..您可以使用

    [carousal scrollToItemAtIndex:3 animated:NO];

这样它就可以在中心显示 3 张图片。

于 2012-08-22T12:19:12.080 回答
0

尝试在创建轮播后删除 reloadData 调用,而是在设置项目数组后将轮播添加为子视图。

于 2012-08-22T12:41:25.610 回答
0

添加下面的代码后,它停止粘住并平滑滚动

它失踪了,

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{
    //implement 'flip3D' style carousel

    //set opacity based on distance from camera
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);

    //do 3d transform
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = carousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * carousel.itemWidth);
}

随着carousel.clipsToBounds = YES;

可能会帮助别人。

于 2012-08-23T09:54:08.950 回答