Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More access to the coverflow cover implementation. Fixing compiler is…

…sues with TKGlobal.
  • Loading branch information...
commit cedd1217c0a0a8cd3ac553c4e6400d88c0c51571 1 parent 9c3ceb3
@devinross authored
View
11 src/TapkuLibrary/TKCoverflowCoverView.h
@@ -37,10 +37,6 @@
*/
@interface TKCoverflowCoverView : UIView {
float baseline;
-
- UIImageView *imageView;
- UIImageView *reflected;
- CAGradientLayer *gradientLayer;
}
- (id) initWithFrame:(CGRect)frame showReflection:(BOOL)reflection;
@@ -54,4 +50,11 @@
/** The height of the image. This property will help coverflow adjust views to display images with different heights. */
@property (assign,nonatomic) float baseline; // set this property for displaying images w/ different heights
+
+
+@property (nonatomic,strong) UIImageView *imageView;
+
+@property (nonatomic,strong) UIImageView *reflected;
+
+
@end
View
70 src/TapkuLibrary/TKCoverflowCoverView.m
@@ -37,7 +37,7 @@
@implementation TKCoverflowCoverView
-@synthesize baseline,gradientLayer;
+@synthesize baseline;
- (id) initWithFrame:(CGRect)frame showReflection:(BOOL)reflection{
@@ -48,21 +48,23 @@ - (id) initWithFrame:(CGRect)frame showReflection:(BOOL)reflection{
self.backgroundColor = [UIColor clearColor];
self.layer.anchorPoint = CGPointMake(0.5, 0.5);
- imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.width)];
- [self addSubview:imageView];
+ self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
+ [self addSubview:self.imageView];
if(reflection){
- reflected = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.frame.size.width, self.frame.size.width, self.frame.size.width)];
- reflected.transform = CGAffineTransformScale(reflected.transform, 1, -1);
- [self addSubview:reflected];
+ CGRect reflectRect = CGRectMakeWithSize(0, self.frame.size.height, self.bounds.size);
- gradientLayer = [CAGradientLayer layer];
- gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:0 alpha:0.5].CGColor,(id)[UIColor colorWithWhite:0 alpha:1].CGColor,nil];
- gradientLayer.startPoint = CGPointMake(0,0);
- gradientLayer.endPoint = CGPointMake(0,0.3);
- gradientLayer.frame = CGRectMake(0, self.frame.size.width, self.frame.size.width, self.frame.size.width);
- [self.layer addSublayer:gradientLayer];
+ self.reflected = [[UIImageView alloc] initWithFrame:reflectRect];
+ self.reflected.transform = CGAffineTransformScale(self.reflected.transform, 1, -1);
+ [self addSubview:self.reflected];
+
+ self.gradientLayer = [CAGradientLayer layer];
+ self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:0 alpha:0.5].CGColor,(id)[UIColor colorWithWhite:0 alpha:1].CGColor,nil];
+ self.gradientLayer.startPoint = CGPointMake(0,0);
+ self.gradientLayer.endPoint = CGPointMake(0,0.3);
+ self.gradientLayer.frame = reflectRect;
+ [self.layer addSublayer:self.gradientLayer];
}
@@ -80,38 +82,48 @@ - (id) initWithFrame:(CGRect)frame {
- (void) setImage:(UIImage *)img{
+
if(img==nil){
- imageView.frame = CGRectZero;
- reflected.frame = CGRectZero;
- reflected.image = imageView.image = nil;
+ [CATransaction begin];
+ [CATransaction setAnimationDuration:0.0f];
+ self.imageView.frame = self.bounds;
+
+ if(self.gradientLayer){
+ self.reflected.image = nil;
+ self.gradientLayer.frame = self.reflected.frame = CGRectMakeWithSize(0,self.frame.size.height,self.bounds.size);
+ }
+ self.imageView.image = nil;
+ [CATransaction commit];
return;
}
- UIImage *image = img;
- float w = image.size.width;
- float h = image.size.height;
- float factor = self.bounds.size.width / (h>w?h:w);
+
+ [CATransaction begin];
+ [CATransaction setAnimationDuration:0.0f];
+
+ UIImage *image = img;
+ CGFloat w = image.size.width;
+ CGFloat h = image.size.height;
+ CGFloat factor = self.bounds.size.width / (h>w?h:w);
h = factor * h;
w = factor * w;
- float y = baseline - h > 0 ? baseline - h : 0;
-
- imageView.frame = CGRectMake(0, y, w, h);
- imageView.image = image;
+ CGFloat y = baseline - h > 0 ? baseline - h : 0;
+ self.imageView.frame = CGRectMake(0, y, w, h);
+ self.imageView.image = image;
if(self.gradientLayer){
-
- gradientLayer.frame = CGRectMake(0, y + h, w, h);
- reflected.frame = CGRectMake(0, y + h, w, h);
- reflected.image = image;
-
+ self.reflected.frame = self.gradientLayer.frame = CGRectMake(0, y + h, w, h);
+ self.reflected.image = image;
}
+ [CATransaction commit];
+
}
- (UIImage*) image{
- return imageView.image;
+ return self.imageView.image;
}
- (void) setBaseline:(float)f{
baseline = f;
View
12 src/TapkuLibrary/TKGlobal.h
@@ -53,18 +53,18 @@
-inline CGRect CGRectMakeWithSize(CGFloat x, CGFloat y, CGSize size);
-inline CGRect CGRectMakeWithSize(CGFloat x, CGFloat y, CGSize size){
+FOUNDATION_STATIC_INLINE CGRect CGRectMakeWithSize(CGFloat x, CGFloat y, CGSize size);
+FOUNDATION_STATIC_INLINE CGRect CGRectMakeWithSize(CGFloat x, CGFloat y, CGSize size){
CGRect r; r.origin.x = x; r.origin.y = y; r.size = size; return r;
}
-inline CGRect CGRectMakeWithPoint(CGPoint origin, CGFloat width, CGFloat height);
-inline CGRect CGRectMakeWithPoint(CGPoint origin, CGFloat width, CGFloat height){
+FOUNDATION_STATIC_INLINE CGRect CGRectMakeWithPoint(CGPoint origin, CGFloat width, CGFloat height);
+FOUNDATION_STATIC_INLINE CGRect CGRectMakeWithPoint(CGPoint origin, CGFloat width, CGFloat height){
CGRect r; r.origin = origin; r.size.width = width; r.size.height = height; return r;
}
-inline CGRect CGRectCompose(CGPoint origin, CGSize size);
-inline CGRect CGRectCompose(CGPoint origin, CGSize size){
+FOUNDATION_STATIC_INLINE CGRect CGRectCompose(CGPoint origin, CGSize size);
+FOUNDATION_STATIC_INLINE CGRect CGRectCompose(CGPoint origin, CGSize size){
CGRect r; r.origin = origin; r.size = size; return r;
}
Please sign in to comment.
Something went wrong with that request. Please try again.