Reputation: 1195
I have a overlay UIView
above a UITableview
. When I scroll the UITableview
, I want the overlay UIView
to move at the same speed as UITableview
scroll,just as the top menu of the facebook app.
Any suggestions? I try to change the overlay uiview's frame in uitableview's scroll delegate.something like:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
self.lastOffsetY = scrollView.contentOffset.y;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offset = self.lastOffsetOfY - scrollView.contentOffset.y;
CGRect frame = self.overlayview.frame;
frame.origin.y += offset;
self.overlayview.frame = frame;
self.lastOffsetOfY = scrollView.contentOffset.y;
}
just use change of contentoffset value. but the overlay uiview doesn't move the same as the uitableview scroll.
Upvotes: 3
Views: 2667
Reputation: 318
If you're trying to accomplish an overlay similar to the Facebook app, it's going to be more efficient to add the overlay to the superview that houses your UITableView/ScollView. This way you won't need to write a bunch of code that needs to execute every time your user scrolls.
//in your View Controller:
UITableView *table = [[[UITableview alloc] init] autorelease];
CGRect frame = CGRectMake (tableOriginX, tableOriginY, width, height);
UIView *overlay = [[[UIView alloc] initWithDesieredFrame: frame] autorelease];
This way the view never moves, but gives the illusion of always existing at the top of the TableView. If, like facebook, you wish to dismiss the view, you can use the TableView's internal gesture recognizers to detect a flick (like facebook) that will dismiss or summon the overlay.
//Something like:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if (velocity.y > 0)
{
[self hideButtonPannelData];
}
if (velocity.y < -0.8)
{
[self revealButtonPannelData];
}
Upvotes: 1
Reputation: 8772
If you just want that UIView to stick to the top of the screen at all times, independent of the tableview you just need to add the UIView to your controller's view instead of adding it to the tableview.
In your XIB, if you're using one, You should have something like
VIEW
UITableView
UIView
Instead of what you probably have:
VIEW
UITableView
UIView
Upvotes: 2