子视图是以栈的方式存放的,也就是说有层次的存放 addSubview: addsubview时都是在最上面面添加 eg:
UIView*v1 = [UIViewnew]; v1.frame 可以看到:[self.view addSubView:xx.view] 其实就等于[self.view insertSubView:xx.view atIndex:
- (void)addSubview:(UIView *)view Parameters view The view to be added. 当然,addsubview也不例外。 Views can have only one superview. 如果当前操作视图已经有另外的一个父视图,则addsubview的操作会把它先从上一个父视图中移除(包括响应者链),再加到新的父视图上面。 addSubview 是将view加到所有层的最顶层 相当于将insertSubview的atIndex参数设置成view.subviews count 即 [view addSubview:oneview addsubview:一个view对象后,release它?
先看代码: IMGView *imgView = [[IMGView alloc] initWithFrame:CGRectMake(10, 0, 300, 300)]; [self.view addSubview 我们逐行分析一下 第一行,alloc一次,imgView对象retainCount为1, 第二行,addSubview一次,此方法会把你传过去的对象retain一次,那么此时它的retainCount为
(wwdcLabel) view.addSubview(visualEffectView) } } 效果 UIGlassEffect.png UIGlassContainerEffect glassEffect) view1.frame = CGRect(x: 10, y: 10, width: 100, height: 50) view1.contentView.addSubview glassEffect) view2.frame = CGRect(x: 110, y: 10, width: 100, height: 50) view2.contentView.addSubview (iOSLabel) visualEffectView.contentView.addSubview(view1) visualEffectView.contentView.addSubview (view2) view.addSubview(visualEffectView) } } 效果 UIGlassContainerEffect.png
:D]; //..E,F,G [self.view addSubview:S]; S.backgroundColor = [UIColor redColor] :A]; UIView *B = [UIView new]; B.mySize = CGSizeMake(100,40); [S addSubview:B]; UIView *C = [UIView new]; C.mySize = CGSizeMake(70,40); [S addSubview:C]; UIView *F = [UIView new]; F.mySize = CGSizeMake(120,60); [S addSubview:F]; [self.view :A]; A.backgroundColor = [UIColor greenColor]; } [self.view addSubview:S];
置于自定义控件的上层,引发界面无响应(注意处理相关方法) I 问题分析 iOS14 UITableViewCell的子试图不能点击或者滑动等手势响应问题,发现有问题的cell基本都是直接 cell.addSubView DebugViewHierarchy视图分析发现问题的原因是:被系统自带的UITableViewCellContentView遮挡在底部了 所以需要改规范的做法 cell.contentView.addSubView [UITableViewCell sensorsdata_swizzleMethod:@selector(addSubview:) withMethod:@selector(kunnan_addSubview [UITableViewCell sensorsdata_swizzleMethod:@selector(addSubview:) withMethod:@selector(kunnan_addSubview { runtime_addSubview(view) } else { self.contentView.addSubview(view)
_replyContent = [[UILabel alloc]init]; _replyContent.numberOfLines = 0; [self.contentView addSubview :_headIMG]; [self.contentView addSubview:_timeL]; [self.contentView addSubview:_nameL]; [self.contentView addSubview:_introL]; [self.contentView addSubview:_imgs]; [self.contentView addSubview:_replyView]; [_replyView addSubview:_replayL]; [_replyView addSubview:_replyContent
self action:@selector(changeBtnFrame:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview self action:@selector(changeBtnFrame2:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview 200, 200)]; redView.backgroundColor = [UIColor redColor]; redView.tag = 11; [self.view addSubview 200)]; blackView.backgroundColor = [UIColor blackColor]; blackView.tag = 12; [self.view addSubview )]; purpleView.backgroundColor = [UIColor purpleColor]; purpleView.tag = 13; [self.view addSubview
When addSubview: is called, the view is placed last among its superview’s subviews; thus it is drawn : v1]; [v1 addSubview: v2]; [mainview addSubview: v3]; Swift: let v1 = UIView(frame:CGRectMake(113, 111 (v1) v1.addSubview(v2) mainview.addSubview(v3) 效果: 5. : v1] [v1 addSubview: v2]; CGRect r = v1.bounds; r.origin.x += 10; r.origin.y += 10; v1.bounds = r; 效果 : v1]; [v1 addSubview: v2]; v1.transform = CGAffineTransformMakeRotation(45 * M_PI/180.0); 效果: 例2:
alloc] initWithImage:image]; [picImageView setFrame:CGRectMake(0, 0, 300,440)]; [picScrollView addSubview :picImageView]; [bgView addSubview:picScrollView]; int nextpage = page +1 ; UIImage *nextimage :nextimage]; [nextImageView setFrame:CGRectMake((nextpage-1)*320+10, 10, 300,440)]; [bgView addSubview bgScorllView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.view addSubview :bgView]; //[self.view addSubview:bgView]; } - (UIView *) viewForZoomingInScrollView:(UIScrollView
I、问题分析 iOS14 UITableViewCell的子试图不能点击或者滑动等手势响应问题,发现有问题的cell基本都是直接 cell.addSubView(tempView1) 这种方式添加的,通过 所以需要改规范的做法 cell.contentView.addSubView(tempView1) 温馨提示:如果你用旧版的Xcode打包,而非使用Xcode12以上版本编译打包的话,是不会有问题。 [UITableViewCell sensorsdata_swizzleMethod:@selector(addSubview:) withMethod:@selector(kunnan_addSubview (@"UITableViewCellContentView")]) {//允许 addSubView UITableViewCellContentView [self [self.contentView addSubview:view]; } } @end 2.2 注意事项 因为此问题涉及的是添加子视图cell.addSubView
text = "用户名" userBgView.addSubview(self.userTextF!) secureTextEntry = true pwdBgView.addSubview(pwdTextF!) image = UIImage(named: "定位.png") self.addSubview(logoImgView!) font = UIFont.systemFontOfSize(17) self.addSubview(buildLabel!) tableFooterView = UIView(frame: CGRectZero) self.view.addSubview(myTableView!)
CGRectMake(0, 170, windowWidth, 80)]; firstRow.image = [UIImage imageNamed:@"1st-row"]; [self.window addSubview CGRectMake(0, 170+80, windowWidth, 80)]; secondRow.image = [UIImage imageNamed:@"2nd-row"]; [self.window addSubview CGRectMake(0, 170+160, windowWidth, 80)]; thirdRow.image = [UIImage imageNamed:@"3rd-row"]; [self.window addSubview CGRectMake(0, 170+320, windowWidth, 80)]; fifthRow.image = [UIImage imageNamed:@"5th-row"]; [self.window addSubview windowWidth, 170, windowWidth, 80)]; firstRow.image = [UIImage imageNamed:@"1st-row"]; [self.window addSubview
layout.marginTop = YGPointValue(64); layout.marginLeft = YGPointValue(0); }]; [self.view addSubview layout.width = YGPointValue(320); layout.height = YGPointValue(80); }]; [self.view addSubview layout.marginTop = YGPointValue(100); layout.padding = YGPointValue(18); }]; [self.view addSubview layout.marginTop = YGPointValue(0); layout.padding = YGPointValue(8); }]; [view addSubview layout.marginTop = YGPointValue(0); layout.padding = YGPointValue(8); }]; [view addSubview
forState:UIControlStateNormal]; _footerBtn.titleLabel.font = [UIFont systemFontOfSize:15]; [self addSubview 问题原因 这是因为,通过Masonry设置约束之前的那个addSubview,会导致layoutSubviews再次执行。 那么,如果你在layoutSubviews中设置addSubview,就导致死循环了。 解决方案 在初始化的时候设置Masonry。 self) { [self initSubViews]; } return self; } 如果你坚持想在layoutSubviews写布局代码,仍然可以,也有个方案: 把addSubview 或者,改用frame和bounds等绝对布局方式,addSubview之后,再用绝对布局,并不会导致layoutSubviews再次执行,例如。
] init]; myView.backgroundColor = [UIColor whiteColor]; myView.frame = rect; [self.view addSubview colorWithRed:0.886 green:0.365 blue:0.247 alpha:1.000]]; self.selectedBtn = findBtn; [myView addSubview alpha:1.000]; findLabel.font = [UIFont systemFontOfSize:10]; findLabel.tag = 101; [myView addSubview ; setUpBtn.tag = 4; setUpBtn.frame = CGRectMake(3 * WIDTH, -20, WIDTH, HEIGHT); [myView addSubview grayColor]; setUpLabel.font = [UIFont systemFontOfSize:10]; setUpLabel.tag = 104; [myView addSubview
testImage.image.size.width, testImage.image.size.height)]; [self.view addSubview faceView.layer.borderWidth = 1; faceView.layer.borderColor = [[UIColor redColor] CGColor]; [self.view addSubview faceFeature.leftEyePosition]; leftEyeView.layer.cornerRadius = faceWidth*0.15; [self.view addSubview faceFeature.rightEyePosition]; leftEye.layer.cornerRadius = faceWidth*0.15; [self.view addSubview setCenter:faceFeature.mouthPosition]; mouth.layer.cornerRadius = faceWidth*0.2; [self.view addSubview
100, 100)]; redV.backgroundColor = [UIColor redColor]; redV.alpha = 0.5; [self.view addSubview lbl.textAlignment = NSTextAlignmentCenter; lbl.backgroundColor = [UIColor blackColor]; [redV addSubview redV.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5]; // redV.alpha = 0.5; [self.view addSubview lbl.textAlignment = NSTextAlignmentCenter; lbl.backgroundColor = [UIColor blackColor]; [redV addSubview
return label }() override func viewDidLoad() { super.viewDidLoad() view.addSubview (expandedLabel) view.addSubview(standardLabel) view.addSubview(condensedLabel) view.addSubview(compressedLabel) } }
UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview let label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = labelTxt self.view.addSubview button.addTarget(self, action:#selector(NewViewController.dismissSelf),for:.touchUpInside) self.view.addSubview