Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

Can you add swipe touch property on webview

$
0
0

@mihir77 wrote:

Hi,

I load an image from my server in a webview..Now i want the user to swipe left and right to load new url.

So can i add touch effect to webview. I tried this way but it didn't work..

_webView = cocos2d::experimental::ui::WebView::create();
    _webView->setContentSize(visibleSize - Size(0,80));
    _webView->setAnchorPoint(Vec2::ZERO);
    _webView->setPosition(Vec2::ZERO);
    _webView->setScalesPageToFit(true);
    _webView->loadURL("http://www.testtest.com/img/1.jpg");

    myLayer->addChild(_webView);

auto listener1 = EventListenerTouchOneByOne::create();
     listener1->setSwallowTouches(true);

 listener1->onTouchBegan = [&](Touch* touch, Event* event){
     pointStartPos=touch->getLocation();
    return true;
 };

listener1->onTouchMoved = [&](Touch* touch, Event* event){
};

 listener1->onTouchEnded = [=](Touch* touch, Event* event){
    pointEndPos=touch->getLocation();
    bool is_left;
    unsigned int i_index=this->currImageIndex;
    if(pointEndPos.x - pointStartPos.x >0) {
        is_left=true;
        i_index--;
    }
    else {
        is_left=false;
        i_index++;
    }
auto dispatcher = Director::getInstance()->getEventDispatcher();
     dispatcher->addEventListenerWithSceneGraphPriority(listener1, this);

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>