Iphone iCarousel在用户选择的索引处停止

Iphone iCarousel在用户选择的索引处停止,iphone,ios,xcode,Iphone,Ios,Xcode,编辑: 我正在制作一个类似老虎机的应用程序,我为老虎机对象添加了iCarousel。 因此,我有一个按钮可以旋转iCarousel。在我的iCarousel视图中,有两个插槽(Slot1和Slot2)。下面是我的iCarouseView:(该框是两个转盘的所在位置) 这就是我如何旋转我的iCarousel: -(IBAction) spin { [carousel1 scrollByNumberOfItems:-35 duration:10.7550f]; [carousel2 scroll

编辑:

我正在制作一个类似老虎机的应用程序,我为老虎机对象添加了
iCarousel
。 因此,我有一个按钮可以旋转
iCarousel
。在我的iCarousel视图中,有两个插槽(Slot1和Slot2)。下面是我的
iCarouseView
:(该框是两个
转盘的所在位置)

这就是我如何旋转我的
iCarousel

-(IBAction) spin {

[carousel1 scrollByNumberOfItems:-35 duration:10.7550f];
[carousel2 scrollByNumberOfItems:-35 duration:10.7550f];

}
下面是我想做的:我想强制让它停止到用户选择的索引

我是这样做的,下面的图像是一个
newViewcontroller
,其中包含
UIImageView
,其中有一个按钮,因此当用户点击它时,我的
CustomPicker
会弹出。My
CustomPicker
包含用户在相机卷上拾取的图像。因此,每个按钮都有一个特定的值发送到my
iCarouseView
。用于插槽1的转盘1和用于插槽2的转盘2

因此,我的问题是旋转旋转木马,然后在特定时间内使其停止到用户选择的所需图像/索引

对不起,我的英语不好。
不扩展UIButton,您可以向按钮添加唯一的标记,从UIEvent的源获取标记

即:


有关传递参数的更多信息,请参见:

为什么不执行tableview的想法,请执行以下例行调用:

[carousel scrollByNumberOfItems:-35 duration:10.7550f];
然后将其放入另一个非操作例程中,让TableView didSelectItemAtIndex方法调用您的新例程,并让您的操作例程调用它

-(void)newRoutineToCall:(int)itemsToMove{
    [carousel scrollByNumberOfItems:itemsToMove duration:10.7550f];
}

-(IBAction) spin {        
    [self newRoutineToCall:-35];
} 
然后实施

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self newRoutineToCall:[indexPath row]];
}

好的,让我试着重新表述这个问题:您有一个图像数组“imageArray”,还有一个特殊的“CarouselImage”(由newViewController选择)。你想让旋转木马旋转N秒,然后降落在特殊的旋转木马上

如果这是正确的,像这样的东西应该会起作用

-(void) spinCarousel: (iCarousel *) carousel toIndex:(NSInteger) targetIndex { 
    NSInteger imagesPerSecond = 5;
    double secondsToScroll = 10.7550f;

    NSUInteger currIndex = [carousel currentItemIndex];
    NSUInteger numItems = [carousel numberOfItems] + [carousel numberOfPlaceholders];
    NSUInteger timesAround = floor(secondsToScroll*imagesPerSecond/numItems);
    NSInteger numToScroll = timesAround*numItems + targetIndex-currIndex;
    [carousel scrollByNumberOfItems:numToScroll duration: secondsToScroll];

}

[self spinCarousel: carousel1 toIndex:[imageArray indexOfItem:carousel1Image]];
[self spinCarousel: carousel2 toIndex:[imageArray indexOfItem:carousel2Image]];
旧答案====

我和其他人一样对目标感到困惑。例如,不清楚“价格”是什么,它与你的老虎机有什么关系?“我希望用户选择他们最后的价格,这意味着我的icarousel可以停止的最后一个视图或图像”抱歉,但这与我对“价格”一词的理解不符

但在最后阅读您的场景:“我想要的是,当用户单击带有阵列中特定图像的UITableViewCell或缩略图时,它会将某些内容/值传递给我的UIButton spin,以便从UITableViewCell中单击的图像将是最后的价格。”我将其解释为旋转按钮需要访问的单个值,或者旋转按钮需要访问的每个图像都有一个值。这两个问题看起来都很简单,所以我不知道为什么会有这样的问题

假设这是第一个(单一价格),那么为什么不能让设置控制器设置一个具有该值的属性(与传递图像NSMutableArray的方式相同)


如果是第二个(每个图像的一个值),那么要么创建两个并行数组,一个带价格,一个带图像,要么创建一个带字典的数组,每个数组都有价格和图像。

这很简单。我以前也做过类似的事情

在以下方法中:

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

   //Configure your view here
   ..... 

  //Add a button on each view of the carousel
  UIButton * someButton = [[UIButton alloc] initWithFrame:view.bounds];
     [someButton setAlpha:0.0];
     [someButton addTarget:self action:@selector(fingerLanded:) forControlEvents:UIControlEventTouchDown];
     [view addSubview:someButton];
     [view bringSubviewToFront:someButton];

    //Add a tag - correspond it to the index
     someButton.tag = index;

   //Make sure the view is user interaction enabled
   [view setUserInteractionEnabled:YES];

    //Also make sure the button can actually receive touches and there is no view 
    //blocking touch events from being sent to the button.

  return view;
}
还加

- (void) fingerLanded:(id) sender{

UIButton * theButtonFingerLandedOn = (UIButton *) sender;

//This is the index the user tapped his finger on
NSUInteger index = theButtonFingerLandedOn.tag;

//Scroll to that particular index
[self.carousel scrollToItemAtIndex:index animated:YES];
- (void) viewDidLoad{

  //You may need this to enable user interaction on a view flying by    
  // Look in the - (void)transformItemViews method of the iCarousel library
  self.carousel.centerItemWhenSelected = NO;

 }
}

还加

- (void) fingerLanded:(id) sender{

UIButton * theButtonFingerLandedOn = (UIButton *) sender;

//This is the index the user tapped his finger on
NSUInteger index = theButtonFingerLandedOn.tag;

//Scroll to that particular index
[self.carousel scrollToItemAtIndex:index animated:YES];
- (void) viewDidLoad{

  //You may need this to enable user interaction on a view flying by    
  // Look in the - (void)transformItemViews method of the iCarousel library
  self.carousel.centerItemWhenSelected = NO;

 }

你必须做类似的事情。希望对你有帮助:)

可能您希望将所有按钮保存在一个数组中,并且每当单击一个按钮时,您都可以确定它是哪一个按钮,即通过检查标记,然后执行方法调用。您能否仅使用一个按钮?当你的旋转计数达到7后,你启动按钮(它会亮起或是其他什么)。然后,当用户点击按钮时,您会查看数组上的当前索引或类似的内容。我可能有点不对劲,因为我不能完全理解你所描述的。你不清楚哪一部分?你能更详细地解释一下你想要实现的目标吗?我已经阅读了你的问题,但不明白“价格”、按钮、表格和icarousel之间的关系。如果你能添加你想要的东西/方式的图片,那将很有帮助。因为我想我们中的很多人不能想象你想要什么!它们位于两个不同的视图控制器中,而不是1。能否通过属性在两个视图控制器之间传递值?对吗?