2

Getting the updated frame with AutoLayouts it is a problem, that I know and been through it's solutions. All solutions are very much efficient but my problem has a limp.

Things I have done :

I have a UIView that I needed to change size of it at demand so I supplied a key setTranslatesAutoresizingMaskIntoConstraints as YES. Because I have created constraints for this UIView and constraints were not letting me change/reflect the frame. Now I am successfully able to change the frame but new problem is view is not giving rendered cordinates [origin(x,y)]. Origin values are not updated.

If I remove setTranslatesAutoresizingMaskIntoConstraints then it works. But I need it.

I have tried other solutions like updating the UI at call using - [view setNeedsLayout] and [view layoutIfNeeded] or delaying the retrieval of rendered frames using -(void)viewDidLayoutSubviews But nothing works.

Community
  • 1
  • 1

2 Answers2

0

if you have some constraints, that doesn't let you change coordinates, then you should change this constraints, but not frame... just create outlets for this constraints, change constant property and use layoutIfNeeded method

aquarium_moose
  • 355
  • 1
  • 11
0

First of all, if you are using auto-layout you need to set translatesAutoresizingMaskIntoConstraints = NO

But back to your question. One thing you could do, is to use KVO (key-value observer) to notify you when the bounds of the view change. For example:

[self.view addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionPrior context:nil];

Then, create an observer method, such as:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

  CGRect frame  = self.view.frame;

}

From frame you should be able to get width and height. Note, that this method may be called multiple times..

yura
  • 1,474
  • 1
  • 12
  • 16