0

我一直在创建几个形状,标签,......在彼此之上。有时它们会按预期显示(以后添加的内容将显示在顶部)但有时不会。我一直在将完全相同的代码添加到 2 个不同的子视图中,这会导致单个项目的显示顺序不同。

使用 zPosition 属性也根本没有帮助......可能会发生什么?

编辑代码添加:这是我在我的子类中运行的函数:

-(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"];
}

它像这样直接从主工作区执行

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];

在 TakePhoto 子类中,transferVariables 函数实际上只是为了能够使用子类中的全局变量。它看起来像这样:

-(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;

}

TakePhoto 子类的 setup-function 看起来像这样(目前有 3 个不同的视图)

-(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"];

}

主要问题是2个图像没有出现。我已经尝试将它们的 zPosition 设置为 10、50 和 100,但它并没有改变任何东西......

4

0 回答 0