简体   繁体   中英

MFMailComposeViewController causes other controls to change position

I have three UIViewControllers being shown modally on top of each other. The third one opens a MFMailComposeViewController and send an email. However, after dismissing that view controller, various controls on other view controllers (not necessarily in the chain of view controllers) have moved in position.

For example, after dismissing the MFMailComposeViewController, one of the labels on the parent ViewController has moved down by about 20px. A scrollview on it's parent has also moved down the same amount. If I enter a separate view controller from here, an imageview is displaced. They always seem to be a control near the top of the screen, and only one per screen.

Has anyone seen this before? I've checked all the code and there nothing which could be causing it. I'm having to reset the frame on these controls every time the screen is shown to prevent them from appearing out of place. But it makes no sense to me.

Thanks.

Have you tried presenting it from the parent view controller?? I had a similar problem and it fixed the issue.

It sounds like layout randomly isn't happening, somehow. I can think of a few things to try:

  • Check that you're not expicitly calling -layoutIfNeeded , especially in places like -setFrame: or -sizeThatFits: — it can cause a layout of the entire view tree, which will tend to do the wrong thing if layout is already happenin (on iOS 5 it can cause inconsistent layout; on iOS 6 I've observed it getting stuck in a layout loop). You also need to be careful around some methods which perform a layout as a side-effect ( UIButton.titleLabel comes to mind — the fix is to call it before adding the view to the hierarchy).
  • If you're using autoresizing then it should just work — except I've seen it not work if the view isn't attached to a window when its frame changes.
  • If you're doing layout in -layoutSubviews , override -setFrame: to call -setNeedsLayout . The usual symptom is that "switch tabs, rotate, switch back" results in an incorrect layout.

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