5

in some iPhone apps i saw a button which was floating over the content view, eg. in the app EyeEm. When the user is scrolling the content, the button remains where it is and is still an interaction element.Overlay Button which is floating over the content view

Ho do I implement this?

My approach would be:

  • Create a view with content
  • Put a button on it
  • But how to make the button floating?

edit:

The floating seems to be the default behavior. Interestingly addSubview and insertSubview have the same behavior when placing the button... both are floating over the content.

- (void)addOverlayButton {
UIButton *oButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[oButton addTarget:self
           action:@selector(aMethod:)
           forControlEvents:UIControlEventTouchDown];
[oButton setTitle:@"Show View" forState:UIControlStateNormal];
oButton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:oButton];
//[self.view insertSubview:oButton aboveSubview:_scrollView];  // same result as addSubview. 
// Both solutions let the button float over the content. 
}
jerik
  • 5,714
  • 8
  • 41
  • 80

2 Answers2

3

Add a subview to your window's content view with insertSubview:aboveSubview: method with your button and scrollview as arguments, but be careful: if two sibling views both have transparency, the resulting drawing behaviour is undefined.

silvansky
  • 2,426
  • 2
  • 19
  • 20
0

if you using storyboard just add button over it, like that

if you want to do with code insertSubview:buttonView aboveSubview:scrollView

no matters its table or scroll view

p.balmasov
  • 357
  • 1
  • 16
  • does work, if in the content area everything is created by the storyboard. But I have content which is created programmatically and in this circumstance the button is not shown. I assume he is hidden under the programmed-content. Perhaps I have to lift the button up somehow, so that the layer is over the programmed-content. – jerik Jun 11 '13 at 10:29