Cyril
Cyril

Reputation: 2818

How to prevent certain object from scrolling in a UIScrollView

I don't know if this is possible and I highly doubt that it is but I'm wondering if there's a way where I can prevent a button for example from scrolling in a UIScrollView using Objective-C programming?

Upvotes: 0

Views: 46

Answers (1)

rmaddy
rmaddy

Reputation: 318794

Sure. Simply update the button's origin as the scroll view scrolls.

In your view controller, implement the appropriate scroll view delegate method. If not done already, setup your view controller as the scroll view's delegate.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    CGRect frame = self.fixedButton.frame;
    frame.origin.y = offset.y + 40;
    self.fixedButton.frame = frame;
}

This will keep the self.fixedButton button 40 points below the top of the visible portion of the scroll view. Adjust as needed.

The above all assumes the button is a subview of the scroll view.

Of course it may be a lot easier if the button and the scroll view share a common parent view. Then the button isn't a subview of the scroll view and won't scroll at all.

Upvotes: 3

Related Questions