0

I want to push a view controller onto the navigation stack but I don't want its view to initially appear - in other words I want the view that was visible when the view controller is push to still be visible.

I tried setting the view controller's view's alpha value to 0.0 which I thought would make it transparent. But instead what is happening is that when I push the view controller on the the stack the screen is white. If I set the alpha to 1.0 then the view controller's view appears as expected.

Why is it white and not transparent?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • What are you trying to accomplish? This seems silly from your explanation. – Christian Jun 01 '12 at 22:01
  • maybe take a screenshot before you push the new view and then use the screenshot as the background imageview of the new view....for screenshot:http://stackoverflow.com/questions/10140907/take-a-screenshot-using-code – Justin Paulson Jun 01 '12 at 22:13
  • Christian. There's an animation that takes place before the view in the pushed vc should appear. If I perform the push after the animation there is a slight but noticable delay as the vc/view loads and draws. So by pushing it first but hidden/transparent it has time to load while the animation takes place (the animation is a view that gets placed in the foreground as a subview of the window). When the animation is over the subview of the window where the animation took place is removed at the same time as the transparent view is made untransparent. – Gruntcakes Jun 01 '12 at 22:56

2 Answers2

1

you will have to add the view to the viewcontrollers manually Not pushing it For example do the following

YourViewController *vc = [[YourViewController alloc] init];
[self.view addSubview:vc.view];

vc.view.alpha = 0.0;

//Animate Here

vc.view.alpha = 1.0;
//Commit Animate Here

Please not that you will have to do some additional coding to implement the release of the vc, since now you have retained vc.view you will not be able to release vc easily,

Another solution is instead of implementing the second view as a viewcontoller implement it as uiview, and the xib class will be view and not uiviewcontroller

Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • The view controller adds a layer that am not sure how you can make it transparent, i tried before to do the same thing you tried, but i never succeded so i always stick to the solution above – Omar Abdelhafith Jun 01 '12 at 22:52
  • As the CALayer can be manipulated instead of the UIView, it ought to be possible to make it transparent one would assume. Did you not find any properties or methods to make it transparent or hidden? – Gruntcakes Jun 01 '12 at 23:01
  • I see a few posting about cutting a "notch" in CALayer, maybe I could experiment with that. – Gruntcakes Jun 01 '12 at 23:04
  • I will try to look further into this, are you pushing the new view with animation or not? – Omar Abdelhafith Jun 01 '12 at 23:07
  • No, its not being set with animation. Meanwhile I'll also try some experiments with your suggestion, but the navigation bar may be an issue due to a few other factors. – Gruntcakes Jun 01 '12 at 23:09
  • also please look at this, http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller i think that what you are trying to achieve is not possible – Omar Abdelhafith Jun 01 '12 at 23:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12048/discussion-between-omar-abdelhafith-and-mungbeans) – Omar Abdelhafith Jun 01 '12 at 23:12
0

Maybe make sure that the opaque property is set to NO?

Or perhaps the view you're pushing on was built in interface builder, and you have a background color of white with another view you put on top of it and you only changed the opacity of the subview?

Jarsen
  • 7,432
  • 6
  • 27
  • 26
  • Thanks for the suggestion, doesn't make a difference however. – Gruntcakes Jun 01 '12 at 22:09
  • I'm not using IB for the view/vc. In its viewDidAppear the backgroundColor is being set to clearColor. There's only one view (which is a UIWebView) in the vc. – Gruntcakes Jun 01 '12 at 22:40