Created
December 17, 2013 19:45
-
-
Save maltzsama/8011348 to your computer and use it in GitHub Desktop.
iCarousel options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "TestViewController.h" | |
| @interface TestViewController () | |
| @property (nonatomic, strong) IBOutlet iCarousel *carousel; | |
| @property (nonatomic, strong) NSArray *informationArray; | |
| @end | |
| @implementation TestViewController | |
| - (void)viewDidLoad{ | |
| self.informationArray = [NSArray arrayWithObjects:@"a", @"b", nil]; | |
| carousel = [[iCarousel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; | |
| carousel.type = iCarouselTypeLinear; | |
| carousel.viewpointOffset = CGSizeMake(0, 5); | |
| [carousel setContentOffset:CGSizeMake(0, 5)]; | |
| carousel.delegate = self; | |
| carousel.dataSource = self; | |
| } | |
| #pragma mark iCarousel Delegate | |
| - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel1 | |
| { | |
| return [self.informationArray count]; | |
| } | |
| - (UIView *)carousel:(iCarousel *)carousel1 viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view | |
| { | |
| UIButton *button = (UIButton *)view; | |
| button = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| button.frame = CGRectMake(0.0, 0.0, xButtonSize, yButtonSize); | |
| button.alpha = 1.0; | |
| button.tag = 1; | |
| return button; | |
| } | |
| //- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carouselLocal{ | |
| // | |
| //} | |
| - (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform | |
| { | |
| //implement 'flip3D' style carousel | |
| transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f); | |
| return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * carousel.itemWidth); | |
| } | |
| //Options of iCaroucel | |
| - (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value{ | |
| //customize carousel display | |
| switch (option) | |
| { | |
| case iCarouselOptionWrap: | |
| { | |
| //normally you would hard-code this to YES or NO | |
| return YES; | |
| } | |
| case iCarouselOptionSpacing: | |
| { | |
| //add a bit of spacing between the item views | |
| return value * 1.05f; | |
| } | |
| case iCarouselOptionFadeMax: | |
| { | |
| if (carousel.type == iCarouselTypeCustom) | |
| { | |
| //set opacity based on distance from camera | |
| return 0.0f; | |
| } | |
| return value; | |
| } | |
| default: | |
| { | |
| return value; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment