Container View made in Storyboard will not change frame programmatically

前端 未结 2 1126
暗喜
暗喜 2021-02-10 22:17

I have a container view, @property (weak, nonatomic) IBOutlet UIView *containerView;, but it won\'t move when I set its frame. Here is how I am trying:



        
相关标签:
2条回答
  • 2021-02-10 22:51

    The "frame" property of a view is used for layout. If you have layout your container view in the storyboard and wanna move it in code. Try the "transform" property. Such as, "self.containerView.transform = CGAffineTransformTranslate(self.containerView.transform, 0.0, 10.0);" => move up the container view for 10 points :)

    0 讨论(0)
  • 2021-02-10 23:03

    The problem I had was the constraints set up in Storyboard were overriding the frame change. This explains why I wasn't having the same issues with programmatically added objects. All I had to do to turn off constraints for the project was to go to the Storyboard.storyboard file, then make sure the "Utilities" sidebar is open and select the "File Inspector" tab. Then I scrolled down under "Interface Builder Document" and deselected "Use Autolayout." After this, I reran the the project to find setting the frame programmatically did work.

    0 讨论(0)
提交回复
热议问题