Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created September 24, 2012 21:38
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/3778566 to your computer and use it in GitHub Desktop.
Save C4Code/3778566 to your computer and use it in GitHub Desktop.
Dragging + Layering
//
// C4WorkSpace.m
// gettingThingsOnScreen
//
// Created by moi on 12-09-23.
// Copyright (c) 2012 moi. All rights reserved.
//
#import "C4WorkSpace.h"
@interface C4WorkSpace ()
-(void)adjustZPos:(NSNotification *)aNotification;
@end
@implementation C4WorkSpace {
C4Shape *s1, *s2;
}
-(void)setup {
s1 = [C4Shape rect:CGRectMake(0, 0, 100, 100)];
s2 = [C4Shape rect:s1.frame];
s2.fillColor = C4GREY;
[s1 addGesture:PAN name:@"pan" action:@"move:"];
[s2 addGesture:PAN name:@"pan" action:@"move:"];
[self.canvas addShape:s1];
[self.canvas addShape:s2];
[self listenFor:@"touchesBegan" fromObject:s1 andRunMethod:@"adjustZPos:"];
[self listenFor:@"touchesBegan" fromObject:s2 andRunMethod:@"adjustZPos:"];
}
-(void)adjustZPos:(NSNotification *)aNotification {
C4Shape *s = (C4Shape *)[aNotification object];
if(s == s1) {
s2.zPosition = 0;
s1.zPosition = 1;
}
else if(s == s2) {
s1.zPosition = 0;
s2.zPosition = 1;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment