简体   繁体   中英

iOS7 storyboard modal segue changes subviews

I have an app with storyboards. I start with view controller A in the storyboard. This VC A has several views/subviews. When running, the user can modify/resize/move these subviews from their originally-loaded locations. It works fine.

Then the user selects and action that results in a modal segue in the storyboard, to view controller B. This loads the VC B properly as normal. BUT, I can see that just as the modal transition is animating to B, the subviews in VC A which were modified by the user, are lost...they revert to the originally-loaded locations. Then when VC B is eventually dismissed and the segue unwinds back to VC A, the views remain back in those original locations -- meaning the user doesn't get the same arrangement of subviews that he had before. It's bad continuity, bad experience.

What's going on here? How can I preserve these subviews through the modal segue and back? I have tried several steps, including saving the subviews' frames (in viewWillDisappear) and restoring them (in viewWillAppear), but it doesn't work...those subviews aren't redrawn in the new locations. I'm assuming these viewWill/viewDid implementations aren't compatible with view movements.

Odd, I also have a collection view whose contents are not lost during the transitions... Seems to just be these subview locations/frames.

I think you for got to use following method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController *destVC = (UIViewController *)segue.destinationViewController;
    destVC.view.backgroundColor = [UIColor blueColor];
}

I think you should change frames or pass on data to other VC through this method.

This is because of auto layout. If auto layout is on (which it is by default), then you should move or resize any views by adjusting their constraints, not setting frames. If you do set frames, as soon as something causes the view to re-draw, the views will revert to the positions defined by their constraints, not the new positions you set them to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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