Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created June 7, 2012 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C4Code/2885789 to your computer and use it in GitHub Desktop.
Save C4Code/2885789 to your computer and use it in GitHub Desktop.
How to set and change layer positions of visible objects
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *zPositionShape;
CGFloat zPosOfLastShape, offset;
NSInteger circleCount;
}
-(void)setup {
offset = 30;
circleCount = (NSInteger)(self.canvas.height/offset)+10;
for(int i = 0; i < circleCount; i++) {
CGFloat x, y, w, h;
w = 10 + (circleCount - i)*offset;
h = w;
x = 384 - w/2.0f;
y = 512 - h/2.0f;
if(i == 0) {
zPositionShape = [C4Shape ellipse:CGRectMake(x,y,w,h)];
zPositionShape.userInteractionEnabled = NO;
zPositionShape.zPosition = i;
zPositionShape.lineWidth = 0.0f;
zPositionShape.fillColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
[self.canvas addShape:zPositionShape];
} else {
C4Shape *s = [C4Shape ellipse:CGRectMake(x,y,w,h)];
s.zPosition = i;
s.fillColor = [C4GREY colorWithAlphaComponent:1.0/offset];
s.lineWidth = 1.0f;
s.userInteractionEnabled = NO;
[self.canvas addShape:s];
}
}
}
-(void)touchesBegan {
zPositionShape.animationDuration = 5.0f;
zPositionShape.animationOptions = AUTOREVERSE | REPEAT | LINEAR;
zPositionShape.zPosition = circleCount;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment