我已将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;
}
答案 0 :(得分:2)
您是否使用了以下方法
- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
//usually this should be slightly wider than the item views
return 240;
}
这个信息在教程中给出..你可以使用
[carousal scrollToItemAtIndex:3 animated:NO];
这样就可以显示中心的3张照片。
答案 1 :(得分:0)
尝试在创建轮播后删除reloadData调用,并在设置items数组后将轮播添加为子视图。
答案 2 :(得分: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;
可以帮助别人。