首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏技术总结

    谈谈addSubview和insertSubview

    子视图是以栈的方式存放的,也就是说有层次的存放 addSubview: addsubview时都是在最上面面添加 eg:

     UIView*v1 = [UIViewnew];
    v1.frame 可以看到:
    
    [self.view addSubView:xx.view] 其实就等于[self.view insertSubView:xx.view atIndex:

    1.3K70发布于 2018-05-22
  • 来自专栏猿人谷

    addSubView需要注意的几个点为什么要在addsubview:一个view对象后,release它?

    - (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它?

    1.6K100发布于 2018-01-17
  • 来自专栏Elton的技术分享博客

    为什么要在addsubview:一个view对象后,release它

    先看代码: IMGView *imgView = [[IMGView alloc] initWithFrame:CGRectMake(10, 0, 300, 300)]; [self.view addSubview 我们逐行分析一下 第一行,alloc一次,imgView对象retainCount为1, 第二行,addSubview一次,此方法会把你传过去的对象retain一次,那么此时它的retainCount为

    50020发布于 2021-01-22
  • 来自专栏学海无涯

    iOS26适配指南之UIVisualEffectView

    (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

    98010编辑于 2025-08-12
  • 来自专栏欧阳大哥的轮子

    iOS下的界面布局利器-MyLayout布局框架

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

    2.4K30发布于 2018-08-22
  • 来自专栏iOS逆向与安全

    iOS小技能: 解决UITableViewCell兼容问题(iOS14适配)

    置于自定义控件的上层,引发界面无响应(注意处理相关方法) 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)

    1.9K30编辑于 2022-08-22
  • 来自专栏Alice

    淘宝评论详情、朋友圈布局masony实现

    _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

    56320发布于 2020-03-27
  • 来自专栏谈补锅

    记录下UIButton的图文妙用和子控件的优先显示

    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

    2.1K30发布于 2018-09-27
  • 来自专栏全栈程序员必看

    绘制图形的视图方式为_三角函数图象的平移变换

    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:

    91520编辑于 2022-08-04
  • 来自专栏c#开发者

    xcode uiscrollview with paging and zoom

    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

    1.5K60发布于 2018-04-12
  • 来自专栏iOS逆向与安全

    iOS14适配【解决UITableViewCell兼容问题(往cell添加子视图的方式不规范)】

    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

    3.1K20发布于 2021-01-18
  • 来自专栏清墨_iOS分享

    自学Swift之路(二)UITableView自定义和实际利用

    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!)

    3.4K90发布于 2018-05-07
  • 来自专栏月亮与二进制

    《Motion Design for iOS》(三十六)

    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

    79420发布于 2021-11-23
  • 来自专栏iOS小生活

    Yoga

    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

    2.3K20发布于 2019-08-12
  • 来自专栏陈满iOS

    iOS小经验·Masonry布局时因不熟悉Cell生命周期而导致死循环

    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再次执行,例如。

    1.9K20发布于 2018-10-09
  • 来自专栏iOS开发~

    iOS_自定义UITabBarController标签视图控制器

    ] 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

    91530编辑于 2022-07-20
  • 来自专栏大师级码师

    利用CIDetector来人脸识别

    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

    64920发布于 2021-10-29
  • 来自专栏DannyHoo的专栏

    视图的alpha属性可能会影响子视图的透明度

    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

    1.3K20发布于 2018-09-13
  • 来自专栏学海无涯

    iOS16适配指南之UIFont

    return label }() override func viewDidLoad() { super.viewDidLoad() view.addSubview (expandedLabel) view.addSubview(standardLabel) view.addSubview(condensedLabel) view.addSubview(compressedLabel) } }

    61820编辑于 2022-09-27
  • 来自专栏sktj

    IOS 弹出框

    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

    3.5K50发布于 2019-07-07
领券