当我选中前一个屏幕时,为什么iCarousel视图中显示的图像显示在上一个屏幕中?

时间:2014-05-30 12:10:26

标签: ios objective-c icarousel

我已经实现了一个iCarousel视图,它在实际屏幕中正常工作,但是当我选中前一个或下一个屏幕时,轮播视图中的图像出现在上一个或下一个屏幕上?

我在[carouselviewname setHidden:YES]中使用了-(void)viewWillDisappear方法;但得到同样的错误。

以下是已使用的轮播链接:

https://github.com/nicklockwood/iCarousel

请帮助我!

这是我的代码:

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

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    return NUMBER_OF_VISIBLE_ITEMS;//1
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    Category *categoryObj = [_categorymAr objectAtIndex:index];
    //create a numbered view
    NSString *imagePath = [[APP_CACHES_DIR stringByAppendingPathComponent:@"catalogues"] stringByAppendingString:[NSString stringWithFormat:@"/%d.jpg", categoryObj.categoryId]];
    if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
        view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IS_IPAD?@"Gallery Placeholder.png":@"Gallery Placeholder.png"]];
    } else {
        view = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[APP_CACHES_DIR stringByAppendingPathComponent:@"catalogues"] stringByAppendingString:[NSString stringWithFormat:@"/%d.jpg", categoryObj.categoryId]]]];
    }



    if (IS_IPAD) {
        view.frame = CGRectMake(0, 0, 420, 420);
    } else {
        view.frame = CGRectMake(0, 0, 200, 200);
    }

    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
    //note: placeholder views are only displayed on some carousels if wrapping is disabled
    return INCLUDE_PLACEHOLDERS? 2: 0;
}

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view;
{
    //create a placeholder view
//  UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    UILabel *label = [[UILabel alloc] initWithFrame:view.bounds];
    label.text = (index == 0)? @"[": @"]";
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = UITextAlignmentCenter;
    label.font = [label.font fontWithSize:50];

    _spacePageControl.currentPage = index;


//  [view addSubview:label];
    return view;
}

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

- (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 = _deptCarousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);

    return CATransform3DTranslate(transform, 0.0, 0.0, offset * _deptCarousel.itemWidth);
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    //wrap all carousels
//    return NO;
    return wrap;
}

- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
    if (index == [self.deptCarousel currentItemIndex]) {
        ProductCategoriesViewController *prodCatView = [[ProductCategoriesViewController alloc] initWithNibName:IS_IPAD ? 
                                                        @"ProductCategoriesView~iPad" : @"ProductCategoriesView" bundle:nil];
        Category *categoryObj = [_categorymAr objectAtIndex:index];
        [prodCatView setStrTitle:categoryObj.categoryName];
        [prodCatView setCategoryId:categoryObj.categoryId];
        [Flurry logEvent:@"Category List" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:categoryObj.categoryName,[NSString stringWithFormat:@"%d",categoryObj.categoryId], nil]];
        [self.navigationController pushViewController:prodCatView animated:YES];
    }
}

1 个答案:

答案 0 :(得分:1)

您是否尝试将clipsToBounds属性设置为YES