开发者

Javascript touch events in a UIWebview that is embedded in a UIScrollview

I have a question with regard to javascript and touch events in a UIWebview, when the UIWebview is embedded inside a UIScrollview.

The UIScrollview has a number of views (I'll call them "subviews" for simplicity) side by side within it. Each subview is the size of the iPad screen and swiping left/right should move on the next/previous subview. One of these subviews is a UIWebview in which I am running a small javascript app which uses touch events and additionally the iScroll component in some cases.

Unfortunately the fact that the UIWebview is embedded inside the UIScrollview (a practise that apple does not recommend: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html - see the box labelled 'important') is out of my hands.

The problem I have is with regard to the touch events when swiping in the UIWebview subview. If I load the google homepage for example the swipe works fine and the next subview moves into view. However when I load one of the JS apps the swipe does not work.

I am assuming the UIWebview component gets the touch events and passes them on to the Jav开发者_如何学编程ascript inside it so that it can respond accordingly. Does it then also propogate them back to the UIScrollview? Or is it up to the Javascript code to ensure that it does not "stopPropagation" on the event? Any info on how these events are co-ordinated would be very much appreciated.

Lastly, I am a javascript programmer not and objective-c programmer, although I understand the basics of it i.e. I have gone thru a fair few of the Stanford iTunes iOS series of Objective-C videos and have coded a few demos, but that's it.

Thanks very much for your time.


Are the failing pages wider than the UIWebView? If you set the scalesPageToFit property to YES and disable the bounces on the internal UIScrollView that the UIWebView uses, that should solve the problem.

You can use the following to disable the bounces:

for (UIView *view in webView.subviews) {
    if (![[view class] isSubclassOfClass:[UIScrollView class]]) continue;
    ((UIScrollView *)view).bounces = NO;
    break;
}

No guarantees about App Store approval though, as I've only used this for apps that weren't distributed through the App Store.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜