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

标签 iphone ios xcode

编辑:

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

enter image description here

这就是我旋转 iCarousel 的方式:

-(IBAction) spin {

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

}

这是我想做的:我想强行让它停止到用户选择的索引处。

我是这样做的,下图是一个 newViewcontroller,其中包含带有按钮的 UIImageView,所以当用户点击它时,我的 CustomPicker 弹出。我的 CustomPicker 包含用户在相机胶卷上选择的图像。所以每个按钮都有一个特定的值发送到我的 iCarouselView。 slot1 的 carousel1 和 slot2 的 carousel2。

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

抱歉我的英语不好。 enter image description here

最佳答案

这很容易。我以前做过类似的事情。

在下面的方法中:

- (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;

 }

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

关于iphone - iCarousel 在用户选择的索引处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10767569/

相关文章:

iphone - UIView 动画时访问临时点

iphone - 有没有办法在iPhone中的离线openstreetmaps sqlite map 图 block 数据库上实现离线地理编码?

ios - 将照片添加到我的应用程序并存储在核心数据中

ios - 在Safari iOS上-播放YouTube视频HTML5播放器会打开并自动关闭

ios - '无法在 descriptionForLayoutAttribute_layoutItem_coefficient 中创建描述。有些东西是零

iphone - 识别当前范围的线程

ios - WKWebView不使用URLCache

iphone - iOS:框架放置不正确

iphone - Xcode:如何将长字符串包裹到 Xcode 编辑器中的下一行

ruby - 使用适用于 Mac OS X 10.7.5 Leopard、Xcode 4.5.2 的 Ruby 完成 ruby​​ 1.9.3 的安装——rvm pkg install openssl 的问题