Question

viewController is composed of 2 main views. A container view and a table view.

The container view is the top section with all the labels such as the day and score.

I want this container view to hide when a user starts scrolling through the days of the table view.

So far I have:

  1. Hooked up an IBOutlet for this container view so I could reference it in the code.
  2. Conformed to the UIScrollViewDelegate
  3. Implimented all required methods for the UITableView

I know UITableView is a subclass of UIScrollView. Without a "proper" UIScrollView I am confused how to go about using the scrollViewDidScroll method and changing the container view alpha to 0 when I am scrolling in the tableView.

I also want the alpha to return to 1 when the user stops scrolling.

thanks.

Note I am not using a UITableViewController

screenshot

Was it helpful?

Solution

You should use a UITableViewController instead of a UIViewController and then drag a UIView in the header section of the UITable. This will cause the UIView to get out of the way on scrolling right out of the box with no coding at all.

OTHER TIPS

If you already set your UITableViewDelegate IBOutlet your controller you will receive all UITableViewDelegate methods from your UITableView as well as all UIScrollViewDelegate methods, should you implement them.

If you would like to hide a particular view when the user starts scrolling I'd use the -scrollViewWillBeginDragging method

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
    [UIView animateWithDuration:0.5f animations:^{
        someView.alpha = 0.0f;
    }];
}

If you would like to show it again after the user stops scrolling, just use the method -scrollViewDidEndDragging:willDecelerate:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
    [UIView animateWithDuration:0.5f animations:^{
        someView.alpha = 1.0f;
    }];
}

Use the following methods directly in controller. They will work :

// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

What have you made UIScrollViewDelegate?

I just took a UITableViewController in my current project and added UIScrollViewDelegate

 @interface YourTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate>

then stuck a comment in

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

and it called once as required (scrollViewDidScroll: will fire repeatedly). So I presume calling one of the UIView animateWithDuration: methods will complete the task you require?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top