如何在自动调整大小后获得帧的大小[英] How to get frame size after autoresize is done

本文是小编为大家收集整理的关于如何在自动调整大小后获得帧的大小的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想知道,如何以及何时(viewDidload,viewwillappear,viewDidappear)可以获得自动化以适合其圆形视图的Uiviews框架大小吗?

推荐答案

从您的问题中尚不清楚为什么要它,但我想是要布局您的子视图.幸运的是,苹果知道您想这样做并实施-(void)layoutSubViews请参阅此信息: nes Layoutsubviews notebviews何时称为? a>

其他推荐答案

我尝试了layoutSubviews,但是它被多次调用,这是一个问题,当我需要自动尺寸的框架以创建CGContext来吸引.

.

我使用的解决方案是在我的自定义UIView上公开init方法,以使其父视图控制器在其viewWillAppear中调用.

我希望有一种方法可以在Custom UIView的实施中完成所有操作,但它使我感到不安(以及Google和Apple的文档等).

其他推荐答案

- (void)viewDidAppear:(BOOL)animated {
    CGFloat uIViewWidth = self.uIView.bounds.size.width;
    CGFloat uIViewHeight = self.uIView.bounds.size.height;
    CGRect uIViewSize = CGRectMake(0, 0, uIViewWidth, uIViewHeight);
}

本文地址:https://www.itbaoku.cn/post/2091147.html

问题描述

I wonder, how and when (viewDidLoad, viewWillAppear, viewDidAppear) can I get a UIViews frame size that was autoresized to fit its partent view?

推荐答案

It's not clear from your question why you want it but I imagine it is to layout your sub views. Luckily Apple knew you would want to do that and implemented -(void)layoutSubViews see this: When is layoutSubviews called?

其他推荐答案

I tried layoutSubviews, but it gets called more than once which is a problem when I need the auto sized frame in order to create a CGContext to draw into.

The solution I used was to expose an init method on my custom UIView for its parent view controller to call in its viewWillAppear.

I wish there was a way to accomplish this all within the custom UIView's implementation, but it eludes me (and Google and Apple's docs and SO).

其他推荐答案

- (void)viewDidAppear:(BOOL)animated {
    CGFloat uIViewWidth = self.uIView.bounds.size.width;
    CGFloat uIViewHeight = self.uIView.bounds.size.height;
    CGRect uIViewSize = CGRectMake(0, 0, uIViewWidth, uIViewHeight);
}