编辑:
我正在制作一个类似于老虎机的应用程序,我为老虎机对象添加了 iCarousel
。
所以我有一个旋转 iCarousel
的按钮。在我的 iCarousel View 中有两个插槽(Slot1 和 Slot2)。下面是我的 iCarouselView
:(框是两个 carousel
所在的位置)
这就是我旋转 iCarousel
的方式:
-(IBAction) spin {
[carousel1 scrollByNumberOfItems:-35 duration:10.7550f];
[carousel2 scrollByNumberOfItems:-35 duration:10.7550f];
}
这是我想做的:我想强行让它停止到用户选择的索引处。
我是这样做的,下图是一个 newViewcontroller
,其中包含带有按钮的 UIImageView
,所以当用户点击它时,我的 CustomPicker
弹出。我的 CustomPicker
包含用户在相机胶卷上选择的图像。所以每个按钮都有一个特定的值发送到我的 iCarouselView
。 slot1 的 carousel1 和 slot2 的 carousel2。
所以我的问题是旋转转盘,然后在特定时间内使其停止到用户选择的所需图像/索引。
抱歉我的英语不好。
最佳答案
这很容易。我以前做过类似的事情。
在下面的方法中:
- (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/