iCarousel停在用户选择的索引上 [英] iCarousel stop at user picked index
问题描述
编辑:
我正在制作类似老虎机的应用,我添加 iCarousel
用于插槽对象。
所以我有一个旋转 iCarousel
的按钮。在我的iCarousel视图中有两个插槽(Slot1和Slot2)。下面是我的 iCarouselView
:(该框是TWO carousel
的地方)
I'm making an app like a Slot Machine, i added iCarousel
for the slot object.
So I have a button that rotates the iCarousel
. In my iCarousel view there are two slots (Slot1 and Slot2). Below is my iCarouselView
: (The box is where the TWO carousel
is)
这是我如何旋转我的 iCarousel
:
-(IBAction) spin {
[carousel1 scrollByNumberOfItems:-35 duration:10.7550f];
[carousel2 scrollByNumberOfItems:-35 duration:10.7550f];
}
这就是我想做的事:我想要的强行让它停在用户选择的索引上。
我这样做了,下面的图片是 newViewcontroller
包含 UIImageView
,其中有一个按钮,所以当用户点击它时,我的 CustomPicker
弹出。我的 CustomPicker
包含用户在相机胶卷上拾取的图像。因此每个按钮都有一个特定值发送到我的 iCarouselView
。 slot1的carousel1和slot2的carousel2。
I have done it this way, the image below is a newViewcontroller
that contains the UIImageView
with a button in it, so when the user taps it, my CustomPicker
pops up. My CustomPicker
contains the image on what the user have picked on the camera roll. So each button has a specific value sent to my iCarouselView
. carousel1 for slot1 and carousel2 for slot2.
所以我的问题是旋转旋转木马,然后在特定的时间内让它停止到所需的用户选择的图像/索引。
So my problem is to spin the carousel and then for a specific time make it stop to the desired image/index the user picks.
抱歉我的英文不好。
Sorry for my bad english.
推荐答案
这很简单。我之前做过类似的事情。
It's easy. I've done something similar before.
在下面的方法中:
- (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;
}
你必须做类似的事情。希望它有用:) !!
You have to do something similar. Hope it was helpful :) !!
这篇关于iCarousel停在用户选择的索引上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!