Search code examples
layoutios7rubymotion

iOS 7 view controller layout issue with transparent/blurred nav bar


I am having trouble with my view controllers in iOS 7. I'm trying to figure out the best way to adjust my view's layout under the nav bar and status bar while maintaining the transparency/blur of the nav bar. So for example, if I have a view controller with:

def viewDidLoad
  @scroll                      = UIScrollView.alloc.initWithFrame(new_frame)
  @scroll.bounces              = true
  @scroll.delegate             = self
  @scroll.alwaysBounceVertical = true
  @scroll.scrollsToTop         = true
  @scroll.contentSize          = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)


  self.view.addSubview(@scroll)
end

My content appears under the nav bar, which I get given the iOS 7 transition guide. To correct that, if I add the following inside of viewDidLoad:

self.edgesForExtendedLayout = UIRectEdgeNone

The layout is adjusted but the navbar no longer has transparency or blur because the view doesn't extend behind it.

If I don't adjust scrollView insets instead of setting edges for layout:

self.automaticallyAdjustsScrollViewInsets = false

Then change my scroll frame to:

def viewDidLoad
  nav_bar_height = self.navigationController.navigationBar.frame.size.height
  status_height  = UIApplication.sharedApplication.statusBarFrame.size.height

  height = nav_bar_height + status_height

  scroll_frame = self.view.bounds

  new_frame = CGRect.new([0, height], [scroll_frame.size.width, scroll_frame.size.height])

  @scroll                      = UIScrollView.alloc.initWithFrame(new_frame)
  @scroll.bounces              = true
  @scroll.delegate             = self
  @scroll.alwaysBounceVertical = true
  @scroll.scrollsToTop         = true
  @scroll.contentSize          = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)


  self.view.addSubview(@scroll)

end

I no longer get the transparent/blur of the nav bar. Only when I adjust the scroll's frame - at the x origin - with a new height does this seem to happen. So I'm wondering why that is and how I can best adjust my scroll without losing the blur/transparency.


Solution

  • Maybe you can try with inset

    [scroll setContentInset:UIEdgeInsetsMake(nav_bar_height + status_height, 0.0, 0.0, 0.0)];
    [scroll setScrollIndicatorInsets:UIEdgeInsetsMake(nav_bar_height + status_height,0.0,0.0,0.0)];
    

    Hope that help