Skip to content

Commit

Permalink
iCarousel now respects the layer.doubleSided property of item views
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Lockwood committed Apr 19, 2012
1 parent de73362 commit 06e212c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 55 deletions.
112 changes: 57 additions & 55 deletions Examples/Basic iOS Demo/iCarouselExampleViewController.m
Expand Up @@ -36,13 +36,13 @@ @implementation iCarouselExampleViewController

- (void)setUp
{
//set up data
wrap = YES;
self.items = [NSMutableArray array];
for (int i = 0; i < NUMBER_OF_ITEMS; i++)
{
[items addObject:[NSNumber numberWithInt:i]];
}
//set up data
wrap = YES;
self.items = [NSMutableArray array];
for (int i = 0; i < NUMBER_OF_ITEMS; i++)
{
[items addObject:[NSNumber numberWithInt:i]];
}
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
Expand All @@ -65,11 +65,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder

- (void)dealloc
{
//it's a good idea to set these to nil here to avoid
//sending messages to a deallocated viewcontroller
carousel.delegate = nil;
carousel.dataSource = nil;
//it's a good idea to set these to nil here to avoid
//sending messages to a deallocated viewcontroller
carousel.delegate = nil;
carousel.dataSource = nil;
[carousel release];
[navItem release];
[orientationBarItem release];
Expand Down Expand Up @@ -187,58 +187,60 @@ - (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;

//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page.png"]] autorelease];
label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50];
[view addSubview:label];
}
else
{
label = [[view subviews] lastObject];
}

UILabel *label = nil;

//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page.png"]] autorelease];
view.layer.doubleSided = NO; //prevent back side of view from showing
label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50];
[view addSubview:label];
}
else
{
label = [[view subviews] lastObject];
}

//set label
label.text = [[items objectAtIndex:index] stringValue];
return view;
label.text = [[items objectAtIndex:index] stringValue];
return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
//note: placeholder views are only displayed on some carousels if wrapping is disabled
return INCLUDE_PLACEHOLDERS? 2: 0;
//note: placeholder views are only displayed on some carousels if wrapping is disabled
return INCLUDE_PLACEHOLDERS? 2: 0;
}

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;

//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page.png"]] autorelease];
label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50.0f];
[view addSubview:label];
}
else
{
label = [[view subviews] lastObject];
}

UILabel *label = nil;

//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"page.png"]] autorelease];
view.layer.doubleSided = NO; //prevent back side of view from showing
label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50.0f];
[view addSubview:label];
}
else
{
label = [[view subviews] lastObject];
}

//set label
label.text = (index == 0)? @"[": @"]";
return view;
label.text = (index == 0)? @"[": @"]";
return view;
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
Expand All @@ -249,7 +251,7 @@ - (CGFloat)carouselItemWidth:(iCarousel *)carousel

- (CGFloat)carousel:(iCarousel *)carousel itemAlphaForOffset:(CGFloat)offset
{
//set opacity based on distance from camera
//set opacity based on distance from camera
return 1.0f - fminf(fmaxf(offset, 0.0f), 1.0f);
}

Expand Down
1 change: 1 addition & 0 deletions RELEASE NOTES.md
Expand Up @@ -2,6 +2,7 @@ Version 1.6.3 beta

- Added offsetForItemAtIndex: method
- Fixed Mac OS scrolling glitch when using numberOfVisibleViews
- iCarousel now respects the layer.doubleSided property of item views

Version 1.6.2

Expand Down
3 changes: 3 additions & 0 deletions iCarousel/iCarousel.m
Expand Up @@ -808,6 +808,9 @@ - (void)transformItemView:(UIView *)view atIndex:(NSInteger)index

#endif

//update backface visibility
view.superview.layer.doubleSided = view.layer.doubleSided;

//special-case logic for iCarouselTypeCoverFlow2
CGFloat clampedOffset = fmaxf(-1.0f, fminf(1.0f, offset));
if (decelerating || (scrolling && !didDrag) || (scrollOffset - [self clampedOffset:scrollOffset]) != 0.0f)
Expand Down

0 comments on commit 06e212c

Please sign in to comment.