如何在iCarousel iphone中实现不同位置图像的删除功能
我将iCarousel作为shownh与旋转木马类型的线性旋转木马一起使用,并实现了删除功能。我能够删除旋转木马中的图像,并且当我尝试删除可见屏幕中的任何其他图像时,它将移动到旋转木马框架并删除。如何在iCarousel iphone中实现不同位置图像的删除功能,iphone,ios,icarousel,Iphone,Ios,Icarousel,我将iCarousel作为shownh与旋转木马类型的线性旋转木马一起使用,并实现了删除功能。我能够删除旋转木马中的图像,并且当我尝试删除可见屏幕中的任何其他图像时,它将移动到旋转木马框架并删除。 我需要从原始位置删除图像 - (void)loadView { [super loadView]; self.view.backgroundColor = [UIColor blackColor]; carousel = [[iCarousel alloc] in
我需要从原始位置删除图像
- (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor blackColor];
carousel = [[iCarousel alloc] initWithFrame:CGRectMake(-130,300, 320, 100)];
carousel.dataSource = self;
carousel.delegate=self;
carousel.type = iCarouselTypeLinear;
carousel.scrollEnabled=YES;
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(60, 50, 200, 200)];
[self.view addSubview:imageView];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIImage *image = [imagesArray objectAtIndex:index];
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0, 60, 60);
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag=index;
NSLog(@"tag is %d",button.tag);
UIButton *deleteButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
deleteButton.frame= CGRectMake(50, -5, 20 ,20);
UIImage *img = [UIImage imageNamed:@"close.png"];
[deleteButton setImage:img forState:UIControlStateNormal];
[deleteButton addTarget:self action:@selector(deleteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button addSubview:deleteButton];
return button;
}
-(void)deleteButtonClicked:(int )sender
{
NSInteger currentIndex = carousel.currentItemIndex;
[carousel removeItemAtIndex:currentIndex animated:YES];
}
请帮帮我
试试这个:
NSInteger index = carousel.currentItemIndex;
[carousel removeItemAtIndex:index animated:YES];
[imagesArray removeObjectAtIndex:index];
还应添加以下内容:
- (void)awakeFromNib
{
if (self) {
//set up carousel data
wrap = NO;
}
}
或者让你的
carousel.type=iCarouselTypeCustom代码>
到
carousel.type=iCarouselTypeLinear代码>
然后实现这个:[carousel reloadData]代码>尝试以下操作:
NSInteger index = carousel.currentItemIndex;
[carousel removeItemAtIndex:index animated:YES];
[imagesArray removeObjectAtIndex:index];
还应添加以下内容:
- (void)awakeFromNib
{
if (self) {
//set up carousel data
wrap = NO;
}
}
或者让你的
carousel.type=iCarouselTypeCustom代码>
到
carousel.type=iCarouselTypeLinear代码>
然后实现这个:[carousel reloadData]代码>您不应该删除carousel.currentItemIndex中的项目,因为该项目不是与您单击的按钮对应的项目,它只是carousel中当前居中的项目
要获取所单击按钮的正确项目索引,请执行以下操作:
-(void)deleteButtonClicked:(id)sender
{
//get the index of the item view containing the button that was clicked
NSInteger index = [carousel indexOfItemViewOrSubview:sender];
//update the data model (always do this first)
[imagesArray removeObjectAtIndex:index];
//remove item from carousel
[carousel removeItemAtIndex:index animated:YES];
}
您不应该删除carousel.currentItemIndex上的项目,因为它不是与您单击的按钮对应的项目,它只是carousel中当前居中的项目
要获取所单击按钮的正确项目索引,请执行以下操作:
-(void)deleteButtonClicked:(id)sender
{
//get the index of the item view containing the button that was clicked
NSInteger index = [carousel indexOfItemViewOrSubview:sender];
//update the data model (always do this first)
[imagesArray removeObjectAtIndex:index];
//remove item from carousel
[carousel removeItemAtIndex:index animated:YES];
}
是否从数组中删除?从原始位置删除图像是什么意思。-(BOOL)carouselshouldwarp:(iCarousel*)carousel{return NO;}我已经在我的代码中使用了它,当它处于当前位置时应该删除。但是使用我的代码,它会滚动到caroselframe位置。我可以编辑或删除位于可见屏幕第一位置的图像从数组中删除吗?从原始位置删除图像是什么意思。-(BOOL)carouselshouldwarp:(iCarousel*)carousel{return NO;}我已经在我的代码中使用了它,当它处于当前位置时应该删除。但是我的代码会滚动到caroselframe位置。我可以编辑或删除位于可见屏幕第一位置的图像,请检查我的编辑。如果我试图删除图像1,当我尝试删除第四个图像时,它会被删除(图像需要删除)在屏幕截图中,它被滚动到第一个图像位置。是否要删除它并保留其位置?当您在iCarousel
中删除一个项目时,它会自动重新定位。wrap=NO;这里我遇到错误,使用了未声明的标识符wrap@属性(非原子)BOOL wrap;
在你的.h中,然后将其合成你的.m.对不起,没有用,当我触摸图像时,它会滚动到旋转传送带帧位置,在那里我可以删除..请检查我的编辑。如果我试图删除图像1,它将被删除,当我尝试删除第4个图像时(图像需要删除)在屏幕截图中,它被滚动到第一个图像位置。是否要删除它并保留其位置?当您在iCarousel
中删除一个项目时,它会自动重新定位。wrap=NO;这里我遇到了错误,使用了未声明的标识符wrap@属性(非原子)BOOL wrap;
在你的.h中,然后将其合成你的.m.对不起,没有用,当我触摸图像时,它会滚动到旋转木马帧位置,在那里我可以删除..我收到这些警告警告:指向整数转换的指针不兼容,初始化“NSInteger”(也称为“int”)和类型为“id”的表达式[3]警告:实例方法'-indexOfitemViewOrSubview:'未找到(返回类型默认为'id')[3],我的应用程序已崩溃。.发件人参数的类型必须为id,而不是原始代码中的int类型。indexOfitemViewOrSubview的“of”后面应大写“i”-这是我的一个输入错误。我收到这些警告警告:指向整数转换的指针不兼容,初始化“NSInteger”(也称为“int”)时使用类型为“id”的表达式[3]警告:实例方法“-indexofitemviewersubview:“未找到”(返回类型默认为“id”)[3]我的应用程序崩溃了。你的发件人参数必须是id类型,而不是原始代码中的int类型。indexOfitemViewOrSubview应该在“of”之后加上大写字母“i”-这是我的输入错误。