Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iOS webview won't scroll down

I am making a system similar to Silverlight's Deep Zoom, in which a very high resolution image is broken into chunks at varying resolutions to allow the impression of scaling from the image filling the screen, to a very detailed portion at any given point. I was frustrated by the lack of a multi scroll option in Android, so I switched to web view. Now it works in Android, but not in iOS. In Android, I can scroll around in both directions, but when I try to scroll down in iOS, it bounces back up as if it is at the end. I tried setting the height to a ridiculous number (5000) but it had no effect. Here is what I am doing now:

var win = Ti.UI.createWindow();
win.orientationModes = [ Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT ];

var webview = Ti.UI.createWebView({
    width:'auto',
    height:5000,
    top:0,
    touchEnabled:true,
    scalesPageToFit:false,
    url:'index.html'
});

win.add(webview);
win.open();

index.html looks like this:

<html>
<style>
img {
padding:0;
margin:0;
float:left;
}
</style>
<body>
<div style="width:1930px;height:640px">
<img src="Layer_3/images/Slice_01.png" width=960 height=640>
<img src="Layer_3/images/Slice_02.png" width=960 height=640>
</div>
<div style="width:1930px;height:640px">
<img src="Layer_3/images/Slice_03.png" width=960 height=640>
<img src="Layer_3/images/Slice_04.png" width=960 height=640>
</div>
</body>
</html>

What is going on here?

— asked January 23rd 2012 by James Borden
  • height
  • ios
  • scroll
  • webview
2 Comments
  • Actually, on Android the reverse problem exists. No matter how small I set the height, I can scroll down into infinity…

    — commented January 23rd 2012 by James Borden
  • Scratch the above comment, my mistake, but the original issue still stands.

    — commented January 23rd 2012 by James Borden

1 Answer

  • Hello,
    Provide scalesPageToFit : true and height of the image in html file as much require to show the partally image in a web view at a time, It will automatically scroll image up and down , when you start zooming the images or when its image size is too big. For this use 1.7.5 or above sdk . You can also try code which i had provided you. .If you want more help then plz let me know .

    Webview automatically listen pinch gesture and by default provide zoom in and out functionality , for this you don't want to put any efforts . All this is possible in titanium using webview. Accept answer if you find usefull … This things work for me.

    var webview = Ti.UI.createWebView({

    width : 100,

    height : 600,

    top : 0,

    backgroundColor:'#00000000',

    scalesPageToFit:true,

    touchEnabled: true,

    });

    wdt = 100;

    hgt = 200;

    img_pth = 'view5_background.png'; // Insert your image url.

    webview.html = '<html><body> <img src="images/'+img_pth+'" width='+wdt+' height='+hgt+'></body></html>';

    win.add(webview);

    Regards

    Moiz

    — answered January 23rd 2012 by Moiz Chhatriwala
    permalink
    6 Comments
    • I already saw this answer in other threads. It is not working for me on iOS. It won't scroll up and down unless I zoom first, even if I set scalesPageToFit to true and put a height of 5000 (more than twice what I need).

      — commented January 23rd 2012 by James Borden
    • Provide the image height of webview around 600 and image height in html around 5000 , this will provide automatic scrolling and add webview in another view. Please try this out.

      — commented January 23rd 2012 by Moiz Chhatriwala
    • Tried that too, still the same old crap. I don't get it. I get the expected behavior on Android, but not iOS.

      — commented January 23rd 2012 by James Borden
    • have you tride the above thing with scalesPageToFit:true, along with reducing the size of your web view and increase the height of image and adding the same in another view. This working for me in the app we made in titanium. Possible in Ios , Which titanium sdk version you are using for this ??

      — commented January 23rd 2012 by Moiz Chhatriwala
    • Have you reduce size of web view and increase the size of image in html to get scrolling and also have you set scalesPageToFit to true along with adding view in scroll view . Provide height of image in html around 5000 and webview height around 600 , and which sdk version of IOS you are working in ???

      — commented January 23rd 2012 by Moiz Chhatriwala
    • Thanks for your answers, but I gave up on this and decided to make my own view instead. I will lock the question.

      — commented January 23rd 2012 by James Borden
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.