swipe pageview with webview in it

  • mihir77
    Likes 0

    Problem Description

    Hi,

    I want to show image loaded from server and swipe left and right to load new images.

    I am using pageview to swipe left and right new pages.

    so when i load the image in a webview, i cannot swipe left and right to load new images but i can swipe left and right on imageview.

    So how can i swipe left and right in a webview..

     

    Heres the code – 

     

    auto pageView = PageView :: create ();
    
        pageView-> ignoreAnchorPointForPosition (false );
        pageView-> setAnchorPoint (Vec2 (0.5, 0.5));
        pageView-> setContentSize (Size (visibleSize.width / 2, visibleSize.height / 2));
        pageView-> setPosition (Vec2 (visibleSize.width / 2, visibleSize.height / 2));
    
        for(int i = 0; i < 4; i++)
        {
            Layout* layout1 = Layout::create();
            layout1->setContentSize(Size(visibleSize.width/2,visibleSize.height/2));
    
           cocos2d::experimental::ui::WebView  *_webView = cocos2d::experimental::ui::WebView::create();       
        _webView->setContentSize(Size(visibleSize.width/4,visibleSize.height/4));
      _webView->setPosition(Point(layout1->getContentSize().width / 2.0f, layout1->getContentSize().height / 2.0f));
        _webView->setScalesPageToFit(true);
        _webView->setTouchEnabled(true);
    
         _webView->loadURL(url);
        layout1->addChild(_webView);
    
        }
        this->addChild (pageView);

    and method :

        void HelloWorld::pageViewEvent(cocos2d::Ref *pSender, cocos2d::ui::PageView::EventType type)
    {
        auto pageView = dynamic_cast<PageView*>(pSender)
        auto index = pageView->getCurPageIndex();
        switch (type)
        {
            case cocos2d::ui::PageView::EventType::TURNING:
            {
                break;               
    
            default:
                break;
        }  
    }

    Also when i add imageview in a scrollview, i cannot swipe pages.

    So how can i swipe pages with webview in it. Is it not possible?

    Also asked on cocos forum – http://discuss.cocos2d-x.org/t/can-you-add-swipe-touch-property-on-webview/30507/7

  • Sonar Systems admin
    Likes 0

    Try adding a webview as a child to the imageview.

  • mihir77
    Likes 0

    No it doesn’t work. How can i make it swipe and load new images. I am stuck here..

  • Sonar Systems admin
    Likes 0

    Can you detect when the user swipes left or right?


    This reply has been verified.
  • mihir77
    Likes 0

    yes, when there is no webview on the pageview, i can detect the swipe but it doesn’t work on the webview, as it scrolls up -down , left – right on the content on the webview when we touch and swipe..

  • mihir77
    Likes 0

    Can you please look into it.. is there some other way?

  • mihir77
    Likes 0

    is there a way to disable left and right swipe in a webview so i can implement my own swiping on webview?

  • Sonar Systems admin
    Likes 0

    Swipe or drag?

  • mihir77
    Likes 0

    I mean we can scroll left – right – up – down the content of the webview..

    so can we disable left right touch scroll in a webview..and instead get it to swipe left and right page view?

    as i dnt need left right scrolling of content but i need up down scrolling..

  • Sonar Systems admin
    Likes 0

    You can’t swipe using only a webview, you need a combo.

  • mihir77
    Likes 0

    Yes, but can you show me how.. I tried a lot but can’t make it work..

  • Henryjames
    Likes 0

    Hey there! I noticed that you're using a PageView to swipe left and right and load new images. It seems that you're facing an issue with swiping left and right in a WebView. One way to address this is by utilizing the concept of SRD status (Self-Regulating Devices). srd status check can be helpful in our daily lives by providing a seamless user experience when navigating through web content. By incorporating touch event listeners and handling swipe gestures within the WebView, you can enable smooth left and right swiping functionality. This will allow users to effortlessly load new images while enjoying the convenience of swiping on the WebView itself. Implementing SRD status in this context will enhance the overall user interaction and make your application even more impressive! Let me know if you need any further assistance or clarification. Good luck with your project!

Login to reply