9

On some occasions, not every time, when my app presents a modal view controller using presentModalViewController:animated: with modalTransitionStyle set to UIModalTransitionStyleFlipHorizontal the iPhone home screen is visible behind the animation. Most of the time the background is black as expected. There is nothing abnormal where I set up the window or rootViewController (a UITabBarController). I blacked out my app UI but you can see the issue in the screen shot taken with an iPhone 4 while the transition is in progress.

What would cause this? I don't know how to do it even if I wanted this behavior.

EDIT: This screen shot was sent to me by a tester, I haven't repro'ed it myself. They told me it occurred during a particular app session and once it occurred it happened for all transitions. When they quit/relaunched the app it didn't happen again and they haven't seen it since. I'm wondering whether it's something I need to be concerned about (i.e. I can prevent it in code).

EDIT 2: This app does not use IB. All controllers/views are created in code.

enter image description here

XJones
  • 21,959
  • 10
  • 67
  • 82
  • This is odd it sounds a bit like a bug. Not ideal if you can't reproduce it. Do you set the background color of the `UIWindow` at any point maybe explicitly setting that might potentially avoid this but that's pure speculation. – Paul.s Dec 29 '11 at 23:43
  • I don't set `backgroundColor` (or any other display properties) of the window. I tried to repro it by explicitly setting the window background color to `clearColor` (and messed with the `tabBarController.view` etc). If I could force this to happen that might give me some insight, haven't found a way to do that yet. – XJones Dec 29 '11 at 23:47
  • Yup that was my thinking. Although the new Apple templates tend to explicitly set the window `self.window.backgroundColor = [UIColor whiteColor];` I could be wrong but chances are it was a similar situation with the xibs pre xcode 4.x – Paul.s Dec 29 '11 at 23:51
  • ah, should also note I'm creating all views/controllers in code, no IB. I'll edit the question to clarify. – XJones Dec 29 '11 at 23:51
  • The main point I was trying to make was that the template explicitly set `self.window.backgroundColor = [UIColor whiteColor];`. The xib stuff was not really relevant. – Paul.s Dec 30 '11 at 01:37
  • I know, thanks for the input. I clarified it in case it spurs any creative ideas for anyone else related to differences between creating windows/views in IB vs programmatically. I am now explicitly setting the window background color as well. Would still be nice to know more about how this happens and be able to force it. – XJones Dec 30 '11 at 01:40
  • Was that tester's device jailbroken? – MattyG Jan 21 '12 at 02:28

5 Answers5

3

I've had the same problem before. Try using [viewController.view setBackgroundColor:[UIColor blackColor]]; on the view your pushing. Worked for me anyways!

Chad
  • 275
  • 3
  • 13
  • thanks, I am now doing that but you may not have saw that in the comments. so far no more repro's. it would be nice to know how to explicitly make it happen other than a random (i.e. buggy) event. – XJones Jan 21 '12 at 02:36
  • Yeah I feel like it's probably more/less a random thing that happens. I only managed to have it happen a few consecutive times on the iPad, happy programming! – Chad Jan 21 '12 at 02:46
  • I'm not sure if this is truly related but I did make this change and as far as I know this has never recurred. I still have never personally seen it. I'll accept this to close it out. – XJones Sep 26 '12 at 16:24
2

This happens when iOS sends memory warning to the app and the app's framework automatically dumps all the view components which are not visible, except the data structures related to the viewController will stay, and when there is a refer to the view it will load the view from the nib again ( in your case loadView is called I guess) you should make sure your view construction code is reconstructable and nullify all objects related to the view components in viewDidUnload method of your view controller.

You can also make it happen by running your app by simulator and when you are in that modal view, trigger the "Memory Warning" simulation from the "Device" menu on the top of your computer screen.

Rhm Akbari
  • 362
  • 3
  • 12
  • This is not the cause of this issue. Your are correct with regard to how iOS (prior to iOS 6) unloads views in response to memory warnings but that is not the issue here. – XJones Sep 26 '12 at 16:22
0

Instructions to fixing this problem:

  1. Go to the effected XIB and select the View Controller effected.
  2. Go to the attributes panel on the right. Go to View >> Background colour.
  3. Now set the colour you want to back the transition.

Hope this helps :)

Seb OH
  • 785
  • 1
  • 6
  • 15
0

I'm not sure but I think this may be caused by a bug or modification to the main 'UIApplication.h' code, a problem with the iOS or an issue with the version of Xcode you have.

Seb

Seb OH
  • 785
  • 1
  • 6
  • 15
0

I saw this issue happening even with Facebook iPhone App. Maybe it is Apple's bug.

Alex Salom
  • 3,074
  • 4
  • 22
  • 33