简体   繁体   中英

How to add a subclass as a subview so that background of subview is set in front of superview

I got 2 classes

@interface PlayScene : UIView

and

@interface GameOverMenu : PlayScene <UITextFieldDelegate>

in PlayScene I create an instance of GameOverMenu

GameOverMenu* gorm = [[GameOverMenu alloc]initWithFrame:CGRectMake(0, 0, 320, 520)];
gorm.backgroundColor = [UIColor blackColor];
[self addSubview:gorm];

But background is set not for subview but for superview, I mean background doesn't hide elements of PlayScene view so that buttons and some drawing remain in front of the background

If the problem is still not clear, I want to make my subview stand in front of superview with black(for example) background, covering the whole screen in front of superview. As if subview class was inherited just from UIView and not from PlayScene

Use any of the below methods :

  • insertSubview: atIndex:
  • insertSubview: aboveSubview:
  • bringSubviewToFront:

EDIT

If you are trying to create an instance of GameOverMenu which is subclass of PlayScene and then add this instance as subview on the view of PlayScene , then probably you can try creating an instance each of PlayScene and GameOverMenu and adding these two as subview to a third view.. maybe ViewControllers view or maybe just a view.. based on your requirement...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM