美文网首页iOS开发-自动布局
masonry 设置圆角时机

masonry 设置圆角时机

作者: 风___________ | 来源:发表于2017-11-22 16:01 被阅读758次

    问题:设置完约束之后是无法立刻获取frame的

    解决:layoutSubviews 视图布局完成之后,此时试图的大小都已经获取到了,在设置

    代码:如下

    - (void)layoutSubviews{
        [super layoutSubviews];
        self.showEmitterView.layer.cornerRadius = self.showEmitterView.width/2;
        self.showCountLabel.layer.cornerRadius = self.showCountLabel.width/2;
        self.showEmitterView.risingY = self.showCountLabel.height/2;
    }
    

    那么问题来了~如果再controller中呢~如何获取view的frame

    解决:看uikit中uiviewcontroller中这一段代码~(看注释)

    // Called just before the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
    - (void)viewWillLayoutSubviews NS_AVAILABLE_IOS(5_0);
    // Called just after the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
    - (void)viewDidLayoutSubviews NS_AVAILABLE_IOS(5_0);
    

    意思就是:重写viewDidLayoutSubviews吧,这个方法能获取到~

    - (void)viewDidLayoutSubviews{
        [super viewDidLayoutSubviews];
        self.showEmitterView.layer.cornerRadius = self.showEmitterView.width/2;
        self.showCountLabel.layer.cornerRadius = self.showCountLabel.width/2;
        self.showEmitterView.risingY = self.showCountLabel.height/2;
    }
    

    相关文章

      网友评论

        本文标题:masonry 设置圆角时机

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