bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    CCSize size = CCDirector::sharedDirector()->getWinSize();
//        创建一个layer作为容器
    CCLayer * containlayer = CCLayer::create();
    CCSprite * sp = CCSprite::create("HelloWorld.png");
    sp->setPosition(ccp(size.width*0.5,size.height*0.5));
    CCSprite * sp2  = CCSprite::create("Default.png");
    
    sp2->setPosition(ccp(sp->getContentSize().width, size.height*0.5));
//    往容器中添加节点
    containlayer->addChild(sp);
    containlayer->addChild(sp2);
    containlayer->setContentSize(CCSizeMake(size.width*3, size.height));
    
//    创建视图添加当前layer
    CCScrollView * sc = CCScrollView::create(CCSizeMake(size.width* 2, size.height));
    addChild(sc);
    
    sc->isDragging();//用户是否正在CCScrollView中操作
    sc->isTouchMoved();//用户是否正在CCScrollView移动操作
    sc->isBounceable();//是否开启弹性效果
    sc->setBounceable(true);//设置CCScrollView有弹性效果
    sc->setViewSize(CCSizeMake(size.width*2, size.height));
//    设置CCScrollView尺寸
    sc->setContainer(containlayer);//设置容器
    sc->getViewSize();//获取视图尺寸
    
//    务必在AppDelegate.cpp 中开启ios多点触莫的支持
    sc->setTouchEnabled(true);//开启监听多触点
    sc->setDelegate(this);//注册监听
    
    return true;
}
 void HelloWorld:: scrollViewDidScroll(CCScrollView * view)
{
    CCLOG("CCScrollView移动");
}
//    当scrollview发生缩放的时相应
 void HelloWorld:: scrollViewDidZoom(CCScrollView * view)
{
    CCLOG("CCScrollView放缩");
}

 

相关文章:

  • 2021-10-18
  • 2021-07-09
  • 2021-07-22
  • 2021-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-08-12
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案