简体   繁体   English

使用自适应布局时可以为UIView设置框架吗

[英]Can I set frame for UIView when use Adaptive Layout

I trying to use setFrame for my UIView, but I also use auto layout on it. 我试图将setFrame用于UIView,但我也对其使用自动布局。 The trouble is I can setFrame for UIView, in spite of use setFrame(x, y, w, h) for it. 麻烦的是,尽管我可以使用setFrame(x, y, w, h)来为UIView设置setFrame(x, y, w, h) I realise because of Adaptive Layout deny it, so can I setFrame for it first at runtime before Adaptive Layout adapt? 我意识到由于Adaptive Layout拒绝它,所以我可以在运行Adaptive Layout之前先在运行时为其设置setFrame吗? Thank you 谢谢

If you are trying to use Adaptive Layout together with Auto Layout you should not think in terms of frames. 如果您尝试将“自适应布局”与“自动布局”一起使用,则不应考虑框架。

However, for edge cases, the Auto Layout engine allows you to do "fine tuning" after it has calculated the position of all the elements. 但是,对于边缘情况,自动布局引擎允许您在计算所有元素的位置后进行“微调”。 Something you could do in your UIView code is to set your layout constraints 您可以在UIView代码中执行的操作是设置布局约束

- (void)updateConstraints {
   [self applyMyViewConstraints];
   [super updateConstraints];
}

After the system updates all the constraints, it will call layoutSubviews in your UIView. 系统更新所有约束后,它将在UIView中调用layoutSubviews At this stage all the frames from the related items are set and final. 在这一阶段,相关项目的所有帧都已设置并最终确定。 You can overwrite the Auto Layout frames that you desire. 您可以覆盖所需的自动版式框架。

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myView.frame = CGRectMake(0, 0, 10, 200);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM