• PageView 类型
    • 索引
      • 属性(properties)
      • 方法
      • 事件
  • Details
    • 属性(properties)
      • sizeMode
      • direction
      • scrollThreshold
      • autoPageTurningThreshold
      • pageTurningEventTiming
      • indicator
      • pageTurningSpeed
      • pageEvents
      • content
      • horizontal
      • vertical
      • inertia
      • brake
      • elastic
      • bounceDuration
      • horizontalScrollBar
      • verticalScrollBar
      • scrollEvents
      • cancelInnerEvents
      • __eventTargets
      • node
      • 示例
      • uuid
      • 示例
      • _enabled
      • enabled
      • 示例
      • enabledInHierarchy
      • 示例
      • _isOnLoadCalled
      • 示例
      • _name
      • _objFlags
      • name
      • 示例
      • isValid
      • 示例
    • 方法
      • getCurrentPageIndex
      • setCurrentPageIndex
        • 参数列表
      • getPages
      • addPage
        • 参数列表
      • insertPage
        • 参数列表
      • removePage
        • 参数列表
      • removePageAtIndex
        • 参数列表
      • removeAllPages
      • scrollToPage
        • 参数列表
      • scrollToBottom
        • 参数列表
      • 示例
      • scrollToTop
        • 参数列表
      • 示例
      • scrollToLeft
        • 参数列表
      • 示例
      • scrollToRight
        • 参数列表
      • 示例
      • scrollToTopLeft
        • 参数列表
      • 示例
      • scrollToTopRight
        • 参数列表
      • 示例
      • scrollToBottomLeft
        • 参数列表
      • 示例
      • scrollToBottomRight
        • 参数列表
      • 示例
      • scrollToOffset
        • 参数列表
      • 示例
      • getScrollOffset
      • getMaxScrollOffset
      • scrollToPercentHorizontal
        • 参数列表
      • 示例
      • scrollTo
        • 参数列表
      • 示例
      • scrollToPercentVertical
        • 参数列表
      • stopAutoScroll
      • setContentPosition
        • 参数列表
      • getContentPosition
      • isScrolling
      • isAutoScrolling
      • update
        • 参数列表
      • lateUpdate
      • __preload
      • onLoad
      • start
      • onEnable
      • onDisable
      • onDestroy
      • onFocusInEditor
      • onLostFocusInEditor
      • resetInEditor
      • addComponent
        • 参数列表
      • 示例
      • getComponent
        • 参数列表
      • 示例
      • getComponents
        • 参数列表
      • 示例
      • getComponentInChildren
        • 参数列表
      • 示例
      • getComponentsInChildren
        • 参数列表
      • 示例
      • _getLocalBounds
        • 参数列表
      • onRestore
      • schedule
        • 参数列表
      • 示例
      • scheduleOnce
        • 参数列表
      • 示例
      • unschedule
        • 参数列表
      • 示例
      • unscheduleAllCallbacks
      • 示例
      • destroy
      • 示例
      • _destruct
      • _onPreDestroy
      • _serialize
        • 参数列表
      • _deserialize
        • 参数列表
    • 事件
  • page-turning Event
  • 索引
  • Details
  • scroll-to-top Event
  • 索引
  • Details
  • scroll-to-bottom Event
  • 索引
  • Details
  • scroll-to-left Event
  • 索引
  • Details
  • scroll-to-right Event
  • 索引
  • Details
  • scrolling Event
  • 索引
  • Details
  • bounce-bottom Event
  • 索引
  • Details
  • bounce-top Event
  • 索引
  • Details
  • bounce-left Event
  • 索引
  • Details
  • bounce-right Event
  • 索引
  • Details
  • scroll-ended Event
  • 索引
  • Details
  • touch-up Event
  • 索引
  • Details
  • scroll-began Event
  • 索引
  • Details

    PageView 类型

    继承于 ScrollView

    模块: cc

    页面视图组件

    索引

    属性(properties)
    • sizeMode PageView.SizeMode 页面视图中每个页面大小类型
    • direction PageView.Direction 页面视图滚动类型
    • scrollThreshold Number 滚动临界值,默认单位百分比,当拖拽超出该数值时,松开会自动滚动下一页,小于时则还原。
    • autoPageTurningThreshold Number 快速滑动翻页临界值。
    • pageTurningEventTiming Number 设置 PageView PageTurning 事件的发送时机。
    • indicator PageViewIndicator 页面视图指示器组件
    • pageTurningSpeed Number 每个页面翻页时所需时间。
    • pageEvents Component.EventHandler[] 滚动视图的事件回调函数
    • content Node 可滚动展示内容的节点。
    • horizontal Boolean 是否开启水平滚动。
    • vertical Boolean 是否开启垂直滚动。
    • inertia Boolean 是否开启滚动惯性。
    • brake Number 开启惯性后,在用户停止触摸后滚动多快停止,0表示永不停止,1表示立刻停止。
    • elastic Boolean 是否允许滚动内容超过边界,并在停止触摸后回弹。
    • bounceDuration Number 回弹持续的时间,0 表示将立即反弹。
    • horizontalScrollBar Scrollbar 水平滚动的 ScrollBar。
    • verticalScrollBar Scrollbar 垂直滚动的 ScrollBar。
    • scrollEvents Component.EventHandler[] 滚动视图的事件回调函数
    • cancelInnerEvents Boolean 如果这个属性被设置为 true,那么滚动行为会取消子节点上注册的触摸事件,默认被设置为 true。
    • __eventTargets Array Register all related EventTargets,…
    • node Node 该组件被附加到的节点。
    • uuid String 组件的 uuid,用于编辑器。
    • _enabled Boolean
    • enabled Boolean 表示该组件自身是否启用。
    • enabledInHierarchy Boolean 表示该组件是否被启用并且所在的节点也处于激活状态。
    • _isOnLoadCalled Number 返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。
    • _name String
    • _objFlags Number
    • name String 该对象的名称。
    • isValid Boolean 表示该对象是否可用(被 destroy 后将不可用)。
    方法
    • getCurrentPageIndex 返回当前页面索引
    • setCurrentPageIndex 设置当前页面索引
    • getPages 返回视图中的所有页面
    • addPage 在当前页面视图的尾部插入一个新视图
    • insertPage 将页面插入指定位置中
    • removePage 移除指定页面
    • removePageAtIndex 移除指定下标的页面
    • removeAllPages 移除所有页面
    • scrollToPage 滚动到指定页面
    • scrollToBottom 视图内容将在规定时间内滚动到视图底部。
    • scrollToTop 视图内容将在规定时间内滚动到视图顶部。
    • scrollToLeft 视图内容将在规定时间内滚动到视图左边。
    • scrollToRight 视图内容将在规定时间内滚动到视图右边。
    • scrollToTopLeft 视图内容将在规定时间内滚动到视图左上角。
    • scrollToTopRight 视图内容将在规定时间内滚动到视图右上角。
    • scrollToBottomLeft 视图内容将在规定时间内滚动到视图左下角。
    • scrollToBottomRight 视图内容将在规定时间内滚动到视图右下角。
    • scrollToOffset 视图内容在规定时间内将滚动到 ScrollView 相对左上角原点的偏移位置, 如果 timeInSecond参数不传,则立即滚动到指定偏移位置。
    • getScrollOffset 获取滚动视图相对于左上角原点的当前滚动偏移
    • getMaxScrollOffset 获取滚动视图最大可以滚动的偏移量
    • scrollToPercentHorizontal 视图内容在规定时间内将滚动到 ScrollView 水平方向的百分比位置上。
    • scrollTo 视图内容在规定时间内进行垂直方向和水平方向的滚动,并且滚动到指定百分比位置上。
    • scrollToPercentVertical 视图内容在规定时间内滚动到 ScrollView 垂直方向的百分比位置上。
    • stopAutoScroll 停止自动滚动, 调用此 API 可以让 Scrollview 立即停止滚动
    • setContentPosition 设置当前视图内容的坐标点。
    • getContentPosition 获取当前视图内容的坐标点。
    • isScrolling 用户是否在拖拽当前滚动视图
    • isAutoScrolling 当前滚动视图是否在惯性滚动
    • update 如果该组件启用,则每帧调用 update。
    • lateUpdate 如果该组件启用,则每帧调用 LateUpdate。
    • __preload __preload is called before every onLoad….
    • onLoad 当附加到一个激活的节点上或者其节点第一次激活时候调用。
    • start 如果该组件第一次启用,则在所有组件的 update 之前调用。
    • onEnable 当该组件被启用,并且它的节点也激活时。
    • onDisable 当该组件被禁用或节点变为无效时调用。
    • onDestroy 该方法为生命周期方法,父类未必会有实现。
    • onFocusInEditor
    • onLostFocusInEditor
    • resetInEditor 用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。
    • addComponent 向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。
    • getComponent 获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
    • getComponents 返回节点上指定类型的所有组件。
    • getComponentInChildren 递归查找所有子节点中第一个匹配指定类型的组件。
    • getComponentsInChildren 递归查找自身或所有子节点中指定类型的组件
    • _getLocalBounds 以便编辑器的场景视图可以正确地执行点选测试。
    • onRestore onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。
    • schedule 调度一个自定义的回调函数。
    • scheduleOnce 调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。
    • unschedule 取消调度一个自定义的回调函数。
    • unscheduleAllCallbacks 取消调度所有已调度的回调函数:定制的回调函数以及 'update' 回调函数。
    • destroy 销毁该对象,并释放所有它对其它对象的引用。
    • _destruct Clear all references in the instance….
    • _onPreDestroy Called before the object being destroyed.
    • _serialize The customized serialization for this object. (Editor Only)
    • _deserialize Init this object from the custom serialized data.
    事件
    • page-turning 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-to-top 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-to-bottom 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-to-left 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-to-right 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scrolling 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • bounce-bottom 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • bounce-top 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • bounce-left 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • bounce-right 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-ended 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • touch-up 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
    • scroll-began 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    Details

    属性(properties)

    sizeMode
    页面视图中每个页面大小类型
    metadescription
    类型PageView.SizeMode
    定义于cocos2d/core/components/CCPageView.js:112
    direction
    页面视图滚动类型
    metadescription
    类型PageView.Direction
    定义于cocos2d/core/components/CCPageView.js:126
    scrollThreshold
    滚动临界值,默认单位百分比,当拖拽超出该数值时,松开会自动滚动下一页,小于时则还原。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCPageView.js:140
    autoPageTurningThreshold
    快速滑动翻页临界值。当用户快速滑动时,会根据滑动开始和结束的距离与时间计算出一个速度值,该值与此临界值相比较,如果大于临界值,则进行自动翻页。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCPageView.js:155
    pageTurningEventTiming
    设置 PageView PageTurning 事件的发送时机。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCPageView.js:172
    indicator
    页面视图指示器组件
    metadescription
    类型PageViewIndicator
    定义于cocos2d/core/components/CCPageView.js:184
    pageTurningSpeed
    每个页面翻页时所需时间。单位:秒
    metadescription
    类型Number
    定义于cocos2d/core/components/CCPageView.js:200
    pageEvents
    滚动视图的事件回调函数
    metadescription
    类型Component.EventHandler[]
    定义于cocos2d/core/components/CCPageView.js:211
    content
    可滚动展示内容的节点。
    metadescription
    类型Node
    定义于cocos2d/core/components/CCScrollView.js:202
    horizontal
    是否开启水平滚动。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCScrollView.js:217
    vertical
    是否开启垂直滚动。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCScrollView.js:228
    inertia
    是否开启滚动惯性。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCScrollView.js:239
    brake
    开启惯性后,在用户停止触摸后滚动多快停止,0表示永不停止,1表示立刻停止。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCScrollView.js:249
    elastic
    是否允许滚动内容超过边界,并在停止触摸后回弹。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCScrollView.js:264
    bounceDuration
    回弹持续的时间,0 表示将立即反弹。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCScrollView.js:275
    horizontalScrollBar
    水平滚动的 ScrollBar。
    metadescription
    类型Scrollbar
    定义于cocos2d/core/components/CCScrollView.js:286
    verticalScrollBar
    垂直滚动的 ScrollBar。
    metadescription
    类型Scrollbar
    定义于cocos2d/core/components/CCScrollView.js:304
    scrollEvents
    滚动视图的事件回调函数
    metadescription
    类型Component.EventHandler[]
    定义于cocos2d/core/components/CCScrollView.js:322
    cancelInnerEvents
    如果这个属性被设置为 true,那么滚动行为会取消子节点上注册的触摸事件,默认被设置为 true。注意,子节点上的 touchstart 事件仍然会触发,触点移动距离非常短的情况下 touchmove 和 touchend 也不会受影响。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCScrollView.js:333
    __eventTargets
    Register all related EventTargets,all event callbacks will be removed in _onPreDestroy
    metadescription
    类型Array
    定义于cocos2d/core/components/CCComponent.js:61
    node
    该组件被附加到的节点。组件总会附加到一个节点。
    metadescription
    类型Node
    定义于cocos2d/core/components/CCComponent.js:75
    示例
    1. cc.log(comp.node);
    uuid
    组件的 uuid,用于编辑器。
    metadescription
    类型String
    定义于cocos2d/core/components/CCComponent.js:106
    示例
    1. cc.log(comp.uuid);
    _enabled

    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCComponent.js:147
    enabled
    表示该组件自身是否启用。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCComponent.js:154
    示例
    1. comp.enabled = true;
    2. cc.log(comp.enabled);
    enabledInHierarchy
    表示该组件是否被启用并且所在的节点也处于激活状态。
    metadescription
    类型Boolean
    定义于cocos2d/core/components/CCComponent.js:185
    示例
    1. cc.log(comp.enabledInHierarchy);
    _isOnLoadCalled
    返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。
    metadescription
    类型Number
    定义于cocos2d/core/components/CCComponent.js:201
    示例
    1. cc.log(this._isOnLoadCalled > 0);
    _name

    metadescription
    类型String
    定义于cocos2d/core/platform/CCObject.js:76
    _objFlags

    metadescription
    类型Number
    定义于cocos2d/core/platform/CCObject.js:83
    name
    该对象的名称。
    metadescription
    类型String
    定义于cocos2d/core/platform/CCObject.js:243
    示例
    1. obj.name = "New Obj";
    isValid
    表示该对象是否可用(被 destroy 后将不可用)。当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
    metadescription
    类型Boolean
    定义于cocos2d/core/platform/CCObject.js:261
    示例
    1. var node = new cc.Node();
    2. cc.log(node.isValid); // true
    3. node.destroy();
    4. cc.log(node.isValid); // true, still valid in this frame
    5. // after a frame...
    6. cc.log(node.isValid); // false, destroyed in the end of last frame

    方法

    getCurrentPageIndex

    返回当前页面索引

    metadescription
    返回Number
    定义于cocos2d/core/components/CCPageView.js:258
    setCurrentPageIndex

    设置当前页面索引

    metadescription
    定义于cocos2d/core/components/CCPageView.js:268
    参数列表
    • index Number
    getPages

    返回视图中的所有页面

    metadescription
    返回Node[]
    定义于cocos2d/core/components/CCPageView.js:278
    addPage

    在当前页面视图的尾部插入一个新视图

    metadescription
    定义于cocos2d/core/components/CCPageView.js:288
    参数列表
    • page Node
    insertPage

    将页面插入指定位置中

    metadescription
    定义于cocos2d/core/components/CCPageView.js:302
    参数列表
    • page Node
    • index Number
    removePage

    移除指定页面

    metadescription
    定义于cocos2d/core/components/CCPageView.js:322
    参数列表
    • page Node
    removePageAtIndex

    移除指定下标的页面

    metadescription
    定义于cocos2d/core/components/CCPageView.js:338
    参数列表
    • index Number
    removeAllPages

    移除所有页面

    metadescription
    定义于cocos2d/core/components/CCPageView.js:354
    scrollToPage

    滚动到指定页面

    metadescription
    定义于cocos2d/core/components/CCPageView.js:368
    参数列表
    • idx Number index of page.
    • timeInSecond Number scrolling time
    scrollToBottom

    视图内容将在规定时间内滚动到视图底部。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:360
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the bottom boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the bottom of the view.
    2. scrollView.scrollToBottom(0.1);
    scrollToTop

    视图内容将在规定时间内滚动到视图顶部。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:385
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the top boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the top of the view.
    2. scrollView.scrollToTop(0.1);
    scrollToLeft

    视图内容将在规定时间内滚动到视图左边。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:410
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the left boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the left of the view.
    2. scrollView.scrollToLeft(0.1);
    scrollToRight

    视图内容将在规定时间内滚动到视图右边。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:435
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the right boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the right of the view.
    2. scrollView.scrollToRight(0.1);
    scrollToTopLeft

    视图内容将在规定时间内滚动到视图左上角。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:460
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the top left boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the upper left corner of the view.
    2. scrollView.scrollToTopLeft(0.1);
    scrollToTopRight

    视图内容将在规定时间内滚动到视图右上角。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:485
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the top right boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the top right corner of the view.
    2. scrollView.scrollToTopRight(0.1);
    scrollToBottomLeft

    视图内容将在规定时间内滚动到视图左下角。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:510
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the bottom left boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the lower left corner of the view.
    2. scrollView.scrollToBottomLeft(0.1);
    scrollToBottomRight

    视图内容将在规定时间内滚动到视图右下角。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:535
    参数列表
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the bottom right boundary immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to the lower right corner of the view.
    2. scrollView.scrollToBottomRight(0.1);
    scrollToOffset

    视图内容在规定时间内将滚动到 ScrollView 相对左上角原点的偏移位置, 如果 timeInSecond参数不传,则立即滚动到指定偏移位置。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:561
    参数列表
    • offset Vec2 A Vec2, the value of which each axis between 0 and maxScrollOffset
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the specific offset of ScrollView immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to middle position in 0.1 second in x-axis
    2. let maxScrollOffset = this.getMaxScrollOffset();
    3. scrollView.scrollToOffset(cc.v2(maxScrollOffset.x / 2, 0), 0.1);
    getScrollOffset

    获取滚动视图相对于左上角原点的当前滚动偏移

    metadescription
    返回Vec2
    定义于cocos2d/core/components/CCScrollView.js:595
    getMaxScrollOffset

    获取滚动视图最大可以滚动的偏移量

    metadescription
    返回Vec2
    定义于cocos2d/core/components/CCScrollView.js:608
    scrollToPercentHorizontal

    视图内容在规定时间内将滚动到 ScrollView 水平方向的百分比位置上。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:625
    参数列表
    • percent Number A value between 0 and 1.
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the horizontal percent position of ScrollView immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Scroll to middle position.
    2. scrollView.scrollToBottomRight(0.5, 0.1);
    scrollTo

    视图内容在规定时间内进行垂直方向和水平方向的滚动,并且滚动到指定百分比位置上。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:651
    参数列表
    • anchor Vec2 A point which will be clamp between cc.v2(0,0) and cc.v2(1,1).
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the percent position of ScrollView immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.
    示例
    1. // Vertical scroll to the bottom of the view.
    2. scrollView.scrollTo(cc.v2(0, 1), 0.1);
    3. // Horizontal scroll to view right.
    4. scrollView.scrollTo(cc.v2(1, 0), 0.1);
    scrollToPercentVertical

    视图内容在规定时间内滚动到 ScrollView 垂直方向的百分比位置上。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:680
    参数列表
    • percent Number A value between 0 and 1.
    • timeInSecond Number Scroll time in second, if you don't pass timeInSecond,the content will jump to the vertical percent position of ScrollView immediately.
    • attenuated Boolean Whether the scroll acceleration attenuated, default is true.// Scroll to middle position.scrollView.scrollToPercentVertical(0.5, 0.1);
    stopAutoScroll

    停止自动滚动, 调用此 API 可以让 Scrollview 立即停止滚动

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:705
    setContentPosition

    设置当前视图内容的坐标点。

    metadescription
    定义于cocos2d/core/components/CCScrollView.js:715
    参数列表
    • position Vec2 The position in content's parent space.
    getContentPosition

    获取当前视图内容的坐标点。

    metadescription
    返回Position
    定义于cocos2d/core/components/CCScrollView.js:730
    isScrolling

    用户是否在拖拽当前滚动视图

    metadescription
    返回Boolean
    定义于cocos2d/core/components/CCScrollView.js:740
    isAutoScrolling

    当前滚动视图是否在惯性滚动

    metadescription
    返回Boolean
    定义于cocos2d/core/components/CCScrollView.js:750
    update

    如果该组件启用,则每帧调用 update。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:222
    参数列表
    • dt Number the delta time in seconds it took to complete the last frame
    lateUpdate

    如果该组件启用,则每帧调用 LateUpdate。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:233
    __preload

    __preload is called before every onLoad.It is used to initialize the builtin components internally,to avoid checking whether onLoad is called before every public method calls.This method should be removed if script priority is supported.

    metadescription
    定义于cocos2d/core/components/CCComponent.js:243
    onLoad

    当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:254
    start

    如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:267
    onEnable

    当该组件被启用,并且它的节点也激活时。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:280
    onDisable

    当该组件被禁用或节点变为无效时调用。该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:290
    onDestroy

    当该组件被销毁时调用该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:300
    onFocusInEditor
    metadescription
    定义于cocos2d/core/components/CCComponent.js:310
    onLostFocusInEditor
    metadescription
    定义于cocos2d/core/components/CCComponent.js:315
    resetInEditor

    用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:320
    addComponent

    向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。

    metadescription
    返回Component
    定义于cocos2d/core/components/CCComponent.js:330
    参数列表
    • typeOrClassName Function | String the constructor or the class name of the component to add
    示例
    1. var sprite = node.addComponent(cc.Sprite);
    2. var test = node.addComponent("Test");
    getComponent

    获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。传入参数也可以是脚本的名称。

    metadescription
    返回Component
    定义于cocos2d/core/components/CCComponent.js:348
    参数列表
    • typeOrClassName Function | String
    示例
    1. // get sprite component.
    2. var sprite = node.getComponent(cc.Sprite);
    3. // get custom test calss.
    4. var test = node.getComponent("Test");
    getComponents

    返回节点上指定类型的所有组件。

    metadescription
    返回Component[]
    定义于cocos2d/core/components/CCComponent.js:372
    参数列表
    • typeOrClassName Function | String
    示例
    1. var sprites = node.getComponents(cc.Sprite);
    2. var tests = node.getComponents("Test");
    getComponentInChildren

    递归查找所有子节点中第一个匹配指定类型的组件。

    metadescription
    返回Component
    定义于cocos2d/core/components/CCComponent.js:390
    参数列表
    • typeOrClassName Function | String
    示例
    1. var sprite = node.getComponentInChildren(cc.Sprite);
    2. var Test = node.getComponentInChildren("Test");
    getComponentsInChildren

    递归查找自身或所有子节点中指定类型的组件

    metadescription
    返回Component[]
    定义于cocos2d/core/components/CCComponent.js:408
    参数列表
    • typeOrClassName Function | String
    示例
    1. var sprites = node.getComponentsInChildren(cc.Sprite);
    2. var tests = node.getComponentsInChildren("Test");
    _getLocalBounds

    如果组件的包围盒与节点不同,您可以实现该方法以提供自定义的轴向对齐的包围盒(AABB),以便编辑器的场景视图可以正确地执行点选测试。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:428
    参数列表
    • out_rect Rect the Rect to receive the bounding box
    onRestore

    onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。如果组件包含了“内部状态”(不在 CCClass 属性中定义的临时成员变量),那么你可能需要实现该方法。编辑器执行撤销/重做操作时,将调用组件的 get set 来录制和还原组件的状态。然而,在极端的情况下,它可能无法良好运作。那么你就应该实现这个方法,手动根据组件的属性同步“内部状态”。一旦你实现这个方法,当用户撤销或重做时,组件的所有 get set 都不会再被调用。这意味着仅仅指定了默认值的属性将被编辑器记录和还原。同样的,编辑可能无法在极端情况下正确地重置您的组件。于是如果你需要支持组件重置菜单,你需要在该方法中手工同步组件属性到“内部状态”。一旦你实现这个方法,组件的所有 get set 都不会在重置操作时被调用。这意味着仅仅指定了默认值的属性将被编辑器重置。此方法仅在编辑器下会被调用。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:441
    schedule

    调度一个自定义的回调函数。如果回调函数已调度,那么将不会重复调度它,只会更新时间间隔参数。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:535
    参数列表
    • callback function The callback function
    • interval Number Tick interval in seconds. 0 means tick every frame.
    • repeat Number The selector will be executed (repeat + 1) times, you can use cc.macro.REPEAT_FOREVER for tick infinitely.
    • delay Number The amount of time that the first tick will wait before execution.
    示例
    1. var timeCallback = function (dt) {
    2. cc.log("time: " + dt);
    3. }
    4. this.schedule(timeCallback, 1);
    scheduleOnce

    调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:572
    参数列表
    • callback function A function wrapped as a selector
    • delay Number The amount of time that the first tick will wait before execution.
    示例
    1. var timeCallback = function (dt) {
    2. cc.log("time: " + dt);
    3. }
    4. this.scheduleOnce(timeCallback, 2);
    unschedule

    取消调度一个自定义的回调函数。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:589
    参数列表
    • callback_fn function A function wrapped as a selector
    示例
    1. this.unschedule(_callback);
    unscheduleAllCallbacks

    取消调度所有已调度的回调函数:定制的回调函数以及 'update' 回调函数。动作不受此方法影响。

    metadescription
    定义于cocos2d/core/components/CCComponent.js:605
    示例
    1. this.unscheduleAllCallbacks();
    destroy

    销毁该对象,并释放所有它对其它对象的引用。实际销毁操作会延迟到当前帧渲染前执行。从下一帧开始,该对象将不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/CCObject.js:296
    示例
    1. obj.destroy();
    _destruct

    Clear all references in the instance.

    NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

    metadescription
    定义于cocos2d/core/platform/CCObject.js:430
    _onPreDestroy

    Called before the object being destroyed.

    metadescription
    定义于cocos2d/core/platform/CCObject.js:463
    _serialize

    The customized serialization for this object. (Editor Only)

    metadescription
    返回object
    定义于cocos2d/core/platform/CCObject.js:488
    参数列表
    • exporting Boolean
    _deserialize

    Init this object from the custom serialized data.

    metadescription
    定义于cocos2d/core/platform/CCObject.js:498
    参数列表
    • data Object the serialized json data
    • ctx _Deserializer

    事件

    page-turning Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-to-top Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-to-bottom Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-to-left Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-to-right Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scrolling Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    bounce-bottom Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    bounce-top Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    bounce-left Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    bounce-right Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-ended Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    touch-up Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details

    scroll-began Event

    模块: cc

    注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。

    索引

    Details