Cocos2d-x tutorial (31)-scroll bar for TableView

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.