为啥当我切换到上一个屏幕时,iCarousel 视图中的图像会显示在上一个屏幕中?
Posted
技术标签:
【中文标题】为啥当我切换到上一个屏幕时,iCarousel 视图中的图像会显示在上一个屏幕中?【英文标题】:Why the image present in the iCarousel view is displayed in the previous screen when I tabbed to previous screen?为什么当我切换到上一个屏幕时,iCarousel 视图中的图像会显示在上一个屏幕中? 【发布时间】:2014-05-30 12:10:25 【问题描述】:我已经实现了一个iCarousel
视图,它在其实际屏幕中正常工作,但是当我切换到上一个或下一个屏幕时,轮播视图中的图像出现在上一个或下一个屏幕上?
我在-(void)viewWillDisappear
中使用了[carouselviewname setHidden:YES]
的方法;但得到同样的错误。
这里是已经使用的轮播链接:
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];
【问题讨论】:
您没有提供足够的信息。根据您的帖子,我的回答是“因为您的代码中有错误”。您需要提供更多信息以及备份它的代码。您的屏幕的组织方式是什么?你在使用导航控制器吗?标签栏控制器?用户如何从一个屏幕进入下一个屏幕?当前项目的信息如何从一个屏幕传递到下一个屏幕?两个屏幕上都有 iCarousels 吗?您希望发生什么,而正在发生什么? 对不起,我正在使用导航控制器,通过它我正在做导航。这是我的代码: 【参考方案1】:您是否尝试将clipsToBounds
属性设置为YES
?
【讨论】:
已经尝试过了,我很高兴我的错误被清除了。谢谢以上是关于为啥当我切换到上一个屏幕时,iCarousel 视图中的图像会显示在上一个屏幕中?的主要内容,如果未能解决你的问题,请参考以下文章