How to get frame size after autoresize is done

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:09:13

问题


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


回答1:


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?




回答2:


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).




回答3:


- (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);
}



回答4:


    NSLog(@"%f; %f; %f; %f;", yourView.frame.origin.x, yourView.frame.origin.y, yourView.frame.size.width, yourView.frame.size.height);

this is how you can get frame of your view



来源:https://stackoverflow.com/questions/7283493/how-to-get-frame-size-after-autoresize-is-done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!