I am working on an iPad application that allows you to control different things in a prototype smart home. For example, it allows you to turn on and off the light. For this, I did UIImageView, which shows the floor plan of the house and added UIButtonsas pods for each lamp that can be switched.

As you can see, the buttons are located perfectly on the floor plan, using the method setFramefor each UIButton. However, when I turn the iPad to portrait orientation, the following happens:

Buttons, obviously, still have the same origin, however this does not apply to changing the position of the image.
The floor plan image has the following settings for struts and springs:

and its content mode is set to Aspect Fit.
My question
as I dynamically rearrange each UIButton, so that it has the same relative position. I suppose I need to handle this in the delegate method {did/should}AutorotateToInterfaceOrientation.
It should be noted that it UIImageViewscales and to handle this, I implemented the delegation method scrollViewDidZoomas follows:
for (UIView *button in _floorPlanImage.subviews) {
CGRect oldFrame = button.frame;
[button.layer setAnchorPoint:CGPointMake(0.5, 1)];
button.frame = oldFrame;
button.transform = CGAffineTransformMakeScale(1.0/scrollView.zoomScale, 1.0/scrollView.zoomScale);
}
Thank you in advance!
source
share