iCarousel stop at user picked index
ios, iphone, xcode
Solution
It's easy. I've done something similar before.
In the following method below:
- (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;
}
Also add
- (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];
}
Also add
- (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 :) !!
Problem
EDIT : 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) This is how I spin my `iCarousel`: ``` -(IBAction) spin { [carousel1 scrollByNumberOfItems:-35 duration:10.7550f]; [carousel2 scrollByNumberOfItems:-35 duration:10.7550f]; } ``` Here is what I wanna do: I want to forcefully make it stop to the index the user picks. 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.