Programing

폰 간격에서 실행되는 앱이 수직으로 스크롤되는 것을 방지하는 방법은 무엇입니까?

lottogame 2020. 12. 14. 07:44
반응형

폰 간격에서 실행되는 앱이 수직으로 스크롤되는 것을 방지하는 방법은 무엇입니까?


나는 전화 간격을 시험하고 있으며 사용자가 화면에서 손가락을 끌 때 내 응용 프로그램이 위아래로 스크롤되지 않도록하고 싶습니다. 이것은 내 코드입니다. 아무도 왜 여전히 스크롤을 허용하는지 말해 줄 수 있습니까?

   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta name = "viewport" content = "user-scalable=no,width=device-width" />
    <!--<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />-->

    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    <!-- iPad/iPhone specific css below, add after your main css >
    <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />        
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />       
    -->
    <!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->
    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js"></script>
    <script type="text/javascript" charset="utf-8">


    // If you want to prevent dragging, uncomment this section
    /*
    function preventBehavior(e) 
    { 
      e.preventDefault(); 
    };
    document.addEventListener("touchmove", preventBehavior, false);
    */

    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    /*
    function handleOpenURL(url)
    {
        // TODO: do something with the url passed in.
    }
    */

    function onBodyLoad()
    {       
        document.addEventListener("deviceready",onDeviceReady,false);
    }

    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    function onDeviceReady()
    {
        // do your thing!
        navigator.notification.alert("PhoneGap is working")
    }
    touchMove = function(event) {
        // Prevent scrolling on this element
        event.preventDefault();
    }

</script>
<style>
#container {
width:100%;
height:100%;
}
</style>

</head>

    <body onload="onBodyLoad()">
        <div id="container" ontouchmove="touchMove(event);">
        </div>
    </body>
</html>

Cordova 2.3.0을 사용하는 경우 + config.xml을 찾아 다음 행을 추가하십시오.

<preference name="UIWebViewBounce" value="false" />

또는 Cordova 2.6.0 + :

<preference name="DisallowOverscroll" value="true" />


페이지가로드 될 때 다음 코드를 실행하여 드래그를 비활성화합니다.

document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);

다음은 jQuery를 사용한 예입니다.

$(document).ready(function() {
    document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
});

구성 파일 사용

<preference name="webviewbounce" value="false" />
<preference name="DisallowOverscroll" value="true" />

Cordova 2.6.0+ find config.xml을 사용하는 경우 다음 행을 추가 / 수정하십시오.

<preference name="DisallowOverscroll" value="true" />


config.xml 파일에 다음 항목을 추가하십시오.

<preference name="DisallowOverscroll" value="true" />

이것이 네이티브 앱인지 웹 앱인지는 말하지 않았습니다.

이것이 기본 앱인 경우 웹보기에서 스크롤을 끌 수 있습니다.

UIScrollView* scroll;  //
for(UIView* theWebSubView in self.webView.subviews){  // where self.webView is the webview you want to stop scrolling.
    if([theWebSubView isKindOfClass:[UIScrollView class] ]){
        scroll = (UIScrollView*) theWebSubView;
        scroll.scrollEnabled = false;
        scroll.bounces = false;
    }
}

otherwise here is a link on the phonegap wiki for preventing scrolling. http://wiki.phonegap.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications


In config.xml of your project, under preferences for iOS set DisallowOverscroll to true. By default it is false which makes whole view to scroll along with inner elements of the view.

<preference name="DisallowOverscroll" value="true" />

For me it work's perfect, when i use the body-selector with jquery. Otherwise i was not able to open external links with Phonegap.

$('body').on('touchmove', function(evt) {
    evt.preventDefault(); 
})

Changed UIWebViewBounce to DisallowOverscroll in 2.6.0


Go native and add this line to the AppDelegate.m file

self.viewController.webView.scrollView.scrollEnabled = false;

Drop it in the - (BOOL)application:(UIApplication)application didFinishLaunchingWithOptions* section.


now you just have to put <preference name="DisallowOverscroll" value="false" /> to <preference name="DisallowOverscroll" value="true" /> in your config.xml file.


At first what you have to do is you should add the event listener in body unload method.

simply put this line in the touch move method.

it won't scroll document.addEventListener("touchstart/touchmove/touchend"). Any one of these 3.

function touchMove (event e) {
    e.preventDefault;
}

If you have UIWebViewBounce to NO in your .plist file.

Then with simple css would make the content not scrollable. Try Adding this style overflow : hidden in your div where you want to disable the scroll.


In config.xml of your project, under preferences for iOS set DisallowOverscroll to true.

참고URL : https://stackoverflow.com/questions/6193016/how-to-prevent-app-running-in-phone-gap-from-scrolling-vertically

반응형