Exemple #1
0
CAScrollView* CAScrollView::createWithFrame(const DRect& rect)
{
    CAScrollView* scrollView = new CAScrollView();
    if (scrollView && scrollView->initWithFrame(rect))
    {
        scrollView->autorelease();
        return scrollView;
    }
    CC_SAFE_DELETE(scrollView);
    return NULL;
}
void ViewController::viewDidLoad()
{

    CAScrollView* scroll = new CAScrollView();
    scroll->initWithFrame(this->getView()->getBounds());
    this->getView()->addSubview(scroll);
    scroll->setViewSize(scroll->getBounds().size * 2);
    scroll->setMaximumZoomScale(3.0f);
    scroll->setMinimumZoomScale(0.5f);
    scroll->setBouncesZoom(false);
    
    CAImageView* v = CAImageView::createWithImage(CAImage::create("1.jpg"));
    v->setFrame(CCRect(0, 0, scroll->getViewSize().width, scroll->getViewSize().height));
    scroll->addSubview(v);
    
    
    ccColor3B color = ccRED;
    if (this->getTitle().compare("view1") == 0)
    {
        color = ccBLACK;
    }
    else if (this->getTitle().compare("view2") == 0)
    {
        scroll->setMaximumZoomScale(1.0f);
        scroll->setMinimumZoomScale(1.0f);
        scroll->setBounces(false);
    }
    else if (this->getTitle().compare("view3") == 0)
    {
        color = ccYELLOW;
    }
    else if (this->getTitle().compare("view4") == 0)
    {
        color = ccGRAY;
        
        scroll->setBounceHorizontal(false);
        
        
    }
    else if (this->getTitle().compare("view5") == 0)
    {
        color = ccRED;
        
        scroll->setBounces(false);
    }

    this->getView()->setColor(color);
}