Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created February 7, 2013 22:55
Show Gist options
  • Save C4Code/4734984 to your computer and use it in GitHub Desktop.
Save C4Code/4734984 to your computer and use it in GitHub Desktop.
zPosition example, a bit wordy.
//
// C4WorkSpace.m
//
// Created by Travis Kirton and Greg Debicki.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
NSArray *shapes;
C4Shape *s1, *s2, *s3;
C4Label *l1, *l2, *l3;
}
-(void)setup {
[self setupShapesAndLabels];
[self listenFor:@"touchesBegan" fromObjects:shapes andRunMethod:@"adjustZPositions:"];
}
-(void)adjustZPositions:(NSNotification *)notification {
C4Shape *touchedShape = (C4Shape *)[notification object];
if(touchedShape.zPosition != 3) {
for(C4Shape *s in shapes) {
if(s == touchedShape) s.zPosition = 3;
else s.zPosition = s.zPosition == 1 ? 1 : s.zPosition - 1;
}
[self setLabels];
}
}
-(void)setLabels {
//FIXME: zPosition should be an integer (maybe)
l1.text = [NSString stringWithFormat:@"%d",(int)s1.zPosition];
l2.text = [NSString stringWithFormat:@"%d",(int)s2.zPosition];
l3.text = [NSString stringWithFormat:@"%d",(int)s3.zPosition];
}
-(void)setupShapesAndLabels {
//FIXME: shape lineWidth needs fixing
CGRect frame = CGRectMake(0, 0, 100, 100);
s1 = [C4Shape ellipse:frame];
s2 = [C4Shape ellipse:frame];
s3 = [C4Shape ellipse:frame];
s1.zPosition = 1;
s2.zPosition = 2;
s3.zPosition = 3;
s1.center = CGPointMake(self.canvas.center.x - 50, self.canvas.center.y - 50);
s2.center = self.canvas.center;
s3.center = CGPointMake(self.canvas.center.x + 50, self.canvas.center.y + 50);
l1 = [C4Label labelWithText:@"1"];
l1.center = CGPointMake(s1.center.x,s1.center.y + s1.height);
l2 = [C4Label labelWithText:@"2"];
l2.center = CGPointMake(s2.center.x,s2.center.y + s2.height);
l3 = [C4Label labelWithText:@"3"];
l3.center = CGPointMake(s3.center.x,s3.center.y + s3.height);
shapes = @[s1,s2,s3];
[self.canvas addObjects:shapes];
[self.canvas addObjects:@[l1,l2,l3]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment