IOS gets the wrong frame after installing autolayout use snapkit

I add a UIView to UIStoryboardand bind it to a custom UIView class called testView, then I create a UIView called subView in the textView in the function require init,

this is my step

1 initialization of subView

2 add a new subView to textView

3 set autorun

4 set cornerRadius (view.frame.height / 2)

After starting the application cornerRadius will not change

then I'm trying to print a subView frame, it gets (0,0,0,0)

this is my code

required init?(coder aDecoder: NSCoder) {
   super.init(coder: aDecoder)

   circelView = UIView()
   self.addSubview(circelView)
   circelView.snp_makeConstraints(closure: { (make) -> Void in
       make.size.equalTo(80)
       make.top.equalTo(self.snp_top)
       make.right.equalTo(self.snp_right)
   })
   print(circelView.frame) //get wrong frame
   circelView.layer.cornerRadius = circelView.frame.size.height / 2
   circelView.layer.masksToBounds = true
}
+4
source share
1 answer

, , . AutoLayout .

, , . , , AutoLayout.

, 'viewDidLayoutSubviews':

override func viewDidLayoutSubviews() {
    print(circelView.frame) // The frame will have been set
    circelView.layer.cornerRadius = circelView.frame.size.height / 2
}

viewDidLayoutSubviews() - UIViewController, , .

+2

Source: https://habr.com/ru/post/1619345/


All Articles