Cocos2d-x tutorial (31)-scroll bar for TableView
In many games, we see similar features:
In, when we slide TableView, the scroll bar below will also slide. When TableView slides to both ends, the scroll bar will be scaled out horizontally, and the scroll bar will also rebound as TableView rebounds, the following describes how to implement the scroll bar function.
First, create a TableView in the project and implement the methods in its protocol. What we need to use is
Virtual void scrollViewDidScroll (CCScrollView * view );
This method is called when sliding TableView. We need to determine the sliding distance of TableView in this method.
Create a new SliderBar file. The content of the SliderBar. h file is as follows:
The content of the SliderBar. cpp file is as follows:
After that, SliderBar still needs to be used in combination with TableView. First, create the tableView and sliderBar objects in the HelloWorld initialization method (do not forget the implementation of the tableView Protocol and related methods, which is omitted here ).
The following code is added to the tableView rolling callback method:
In this way, you can see the above effect.