I've been creating a couple of shapes, labels,... on top of each other. sometimes they are displayed as expected (whatever is added later will appear on top) but sometimes it doesn't.. I've been adding the exact same code to 2 different subviews and it results in different display orders of the single items.
using the zPosition property also doesn't help at all... What might be happening?
EDIT CODE ADDED: this is the function I'm running in my subclass:
-(void)topBarSetup{
//--------------------------------------------------
//underlying rect
//--------------------------------------------------
topNavBar=[C4Shape rect:CGRectMake(0, topBarFromTop, self.canvas.width, topBarHeight)];
topNavBar.fillColor=navBarColor;
topNavBar.lineWidth=0;
[self.canvas addShape:topNavBar];
//center label
titleLabel = [C4Label labelWithText:@"Add Photo Letter" font:fatFont];
titleLabel.center=topNavBar.center;
[self.canvas addLabel:titleLabel];
//--------------------------------------------------
//LEFT
//--------------------------------------------------
//back text
backLabel=[C4Label labelWithText:@"Back" font: normalFont];
backLabel.center=CGPointMake(40, topNavBar.center.y);
[self.canvas addLabel:backLabel];
//back icon
//backButtonImage=iconBack;
backButtonImage.width= 12.2;
backButtonImage.center=CGPointMake(10, topNavBar.center.y);
[self.canvas addImage:backButtonImage];
//invisible rect to interact with
navigateBackRect=[C4Shape rect: CGRectMake(0, topBarFromTop, 60, topNavBar.height)];
navigateBackRect.fillColor=navigationColor; //this color has an alpha of 0
navigateBackRect.lineWidth=0;
[self.canvas addShape:navigateBackRect];
[self listenFor:@"touchesBegan" fromObject:navigateBackRect andRunMethod:@"navigateBack"];
//--------------------------------------------------
//RIGHT
//--------------------------------------------------
//close icon
closeButtonImage=iconClose;
closeButtonImage.width= 25;
closeButtonImage.center=CGPointMake(self.canvas.width-18, topNavBar.center.y);
//closeButtonImage.zPosition=2;
[self.canvas addImage:closeButtonImage];
//invisible rect to interact with
closeRect=[C4Shape rect:CGRectMake(self.canvas.width-35, topBarFromTop, 35, topNavBar.height)];
closeRect.fillColor=navigationColor; //this color has an alpha of 0
closeRect.lineWidth=0;
// closeRect.zPosition=3;
[self.canvas addShape:closeRect];
[self listenFor:@"touchesBegan" fromObject:closeRect andRunMethod:@"goToAlphabetsView"];
}
It's executed directly from the main workspace like this
takePhoto= [TakePhoto new];
takePhoto.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
takePhoto.canvas.userInteractionEnabled = YES;
[takePhoto transferVariables:1 topBarFromTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconTakePhoto:iconTakePhoto iconClose:iconClose iconBack:iconBack];
[takePhoto setup];
[self.canvas addSubview:takePhoto.canvas];
in the TakePhoto subclass the transferVariables function is really just to be able to use the global variables in the subclass. It looks like this:
-(void)transferVariables:(int)number topBarFromTop:(float)TopBarFromTopDefault topBarHeight:(float)TopNavBarHeightDefault bottomBarHeight:(float)BottomBarHeightDefault navBarColor:(UIColor*)navBarColorDefault navigationColor:(UIColor*)navigationColorDefault typeColor:(UIColor*)typeColorDefault fatFont:(C4Font*)fatFontDefault normalFont:(C4Font*)normalFontDefault iconTakePhoto:(C4Image*)iconTakePhotoDefault iconClose:(C4Image*)iconCloseDefault iconBack:(C4Image*)iconBackDefault{
//nav bar heights
topBarFromTop=TopBarFromTopDefault;
topBarHeight=TopNavBarHeightDefault;
bottomBarHeight=BottomBarHeightDefault;
//colors
navBarColor=navBarColorDefault;
navigationColor=navigationColorDefault;
typeColor=typeColorDefault;
//fonts
fatFont=fatFontDefault;
normalFont=normalFontDefault;
//icons
iconTakePhoto=iconTakePhotoDefault;
iconClose=iconCloseDefault;
backButtonImage=iconBackDefault;
}
and the setup-function of the TakePhoto subclass looks like this (3 different views at the moment)
-(void)setup {
//setup all the default variables
//>colors
navBarColorDefault=[UIColor colorWithRed:0.96875 green:0.96875 blue:0.96875 alpha:1];
navigationColorDefault=[UIColor colorWithRed:0 green:0 blue:0 alpha:0];
buttonColorDefault= [UIColor colorWithRed:0.8984275 green:0.8984275 blue:0.8984275 alpha:1];
typeColorDefault=[UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:1];
overlayColorDefault=[UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:0.5];
highlightColorDefault=[UIColor colorWithRed:0.757 green:0.964 blue:0.617 alpha:0.5];
//>nav bar heights
TopBarFromTopDefault= 20.558;
TopNavBarHeightDefault= 44.0;
BottomBarHeightDefault= 49;
//>type/fonts
fatFontDefault= [C4Font fontWithName:@"HelveticaNeue-Bold" size:17];
normalFontDefault= [C4Font fontWithName:@"HelveticaNeue" size:17];
//>icons
iconTakePhoto= [C4Image imageNamed:@"icon_TakePhoto.png"];
iconClose= [C4Image imageNamed:@"icon_Close.png"];
iconBack= [C4Image imageNamed:@"icon_back.png"];
iconOk= [C4Image imageNamed:@"icon_OK.png"];
iconSettings= [C4Image imageNamed:@"icon_Settings.png"];
id)createViews{
//TakePhoto
takePhoto= [TakePhoto new];
takePhoto.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
takePhoto.canvas.userInteractionEnabled = YES;
[takePhoto transferVariables:1 topBarFromTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconTakePhoto:iconTakePhoto iconClose:iconClose iconBack:iconBack];
[takePhoto setup];
[self.canvas addSubview:takePhoto.canvas];
//CropPhoto
cropPhoto=[CropPhoto new];
cropPhoto.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
cropPhoto.canvas.userInteractionEnabled=YES;
[cropPhoto transferVariables:1 topBarFroTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault overlayColor:overlayColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconClose:iconClose iconBack:iconBack iconOk:iconOk];
[self.canvas addSubview:cropPhoto.canvas];
cropPhoto.canvas.hidden= YES;
//AssignPhoto
assignLetter=[AssignLetter new];
assignLetter.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
assignLetter.canvas.userInteractionEnabled=YES;
[assignLetter transferVariables:1 topBarFroTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault highlightColor:highlightColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconClose:iconClose iconBack:iconBack iconOk:iconOk iconSettings:iconSettings];
[assignLetter setup];
[self.canvas addSubview:assignLetter.canvas ];
assignLetter.canvas.hidden=YES;
//the methods to listen for from all other canvasses
[self listenFor:@"goToTakePhoto" andRunMethod:@"goToTakePhoto"];
[self listenFor:@"goToCropPhoto" andRunMethod:@"goToCropPhoto"];
[self listenFor:@"goToAssignPhoto" andRunMethod:@"goToAssignPhoto"];
}
The main problem is that the 2 images don't appear. I have experimented setting their zPosition to 10, 50 and 100, but it doesn't change anything...