美文网首页
Frame和bounds

Frame和bounds

作者: 一__谷__作气 | 来源:发表于2019-09-26 21:25 被阅读0次

写了一个纯代码tableView嵌套collectionView的demo,最后结束的时候发现图片显示乱七八糟,初始以为是使用的第三方SDWebImage加载图片导致的错乱,找一圈,发现没什么错误,又怀疑是cell复用的问题,重新写了代码之后发现问题还是老样子。真的是不知道哪里错了,就重新写了带xib的UI显示,发现正常了。所以问题总结在collectionviewcell的自定义初始化方法上,原来的代码如下

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor cyanColor];
        self.img = [[UIImageView alloc]initWithFrame:frame];
        self.vipOrNot = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width-30, 5, 30, 10)];
        self.img.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:self.img];
        [self addSubview:self.vipOrNot];
    }
    return self;
}

看起来貌似没问题。。。。
为了一点一点排查,我一行一行的改,运气还不错第一行就找到了错误:
self.img = [[UIImageView alloc]initWithFrame:frame]; 就是这个frame参数
,一定不能用frame来定义imageView的位置。
又去查了下frame和bounds的关系。真的是细思极恐。

具体见下链接,别人写得更好,我就不班门弄斧了
https://www.jianshu.com/p/964313cfbdaa

相关文章

  • iOS 面试题目

    1、iOS frame和Bounds 以及frame和bounds区别2、 ios webView 加载HTML字...

  • bounds、scrollView滚动原理

    bounds本质:修改内容原点位置。frame和bounds都是描述的一个矩形。frame:可视范围bounds:...

  • iOS学习心得之:frame & bounds

    frame & bounds 浅显的理解的话 ** frame ** 代表元素的位置和大小.而 bounds 值...

  • bounds

    当bounds大小不变时不会影响frame,但是当bounds大小改变时会影响frame原点和大小,bounds原...

  • iOS纪录

    (1)View的Frame与Bounds区别 摘自 ios view的frame和bounds之区别(位置和大小)...

  • 深入探究frame和bounds的区别以及setbounds使用

    深入探究frame和bounds的区别以及setbounds使用 深入探究frame和bounds的区别以及set...

  • bounds和frame

    bounds的设置会改变frame,改变的计算方式是什么?

  • Bounds和frame

    frame:以父控件左上角为原点,描述可视范围。 bounds:以自己的左上角为原点,描述可视范围在内容的区域。所...

  • Frame和bounds

    写了一个纯代码tableView嵌套collectionView的demo,最后结束的时候发现图片显示乱七八糟,初...

  • frame 和 bounds

    修改 bounds 不会影响 frame 修改 bounds 只会影响子 View 的显示位置,左正右负,上正下负

网友评论

      本文标题:Frame和bounds

      本文链接:https://www.haomeiwen.com/subject/yqghyctx.html