2017-11-24 7 views
0

iOS 응용 프로그램에 HTML, Java 스크립트 코드를로드하고 있습니다. 잘 작동하지만 장치 높이에 따라 애니메이션 크기 (너비)를 변경해야합니다. 다음 코드를 시도했지만 자바 스크립트를 iOS로 호출하는 것은 매우 새로운 기능입니다.iOS에서 컨테이너의 너비를 동적으로 변경하는 방법 (Objective-C)

자바 스크립트의 내 HTML 페이지 코드는

  var $ios9 = document.getElementById('container-ios9'); 
     var SW9 = new Wave9({ 
           width: 800, 
           height: 40, 
           container: $ios9, 
           }); 
     </script> 

내가 위의 코드는 폭을 변경하지 않는

if (self.view.frame.size.width <= 400) { 
[_animationWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('container-ios9').width = 500"]; 
} 
else { 
    [_animationWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('container-ios9').width = 700"]; 
} 

으로 네이티브 코드로 호출하고, 그래서, 은 누구도 날을 제안 할 수 , 이것을 고치는 방법. 감사!

+0

. width'은 잘못된 것입니다. document.getElementById ('container-ios9'). style.width' – Sankar

+0

이 말이 맞습니다. [_animationWebView stringByEvaluatingJavaScriptFromString : @ "document.getElementById ('container-ios9'). style.width = 400"] ; ? –

+0

예. 또한,'document.getElement ById ('container-ios9') .style.width = '400px '' 시도 했습니까? – Sankar

답변

0

많은 R & D 이후, 직접 문제를 해결했습니다. 나는이 대답을 여기에 올리고있다, 그것은 누군가 미래를 도울 것이다. HTML 파일, 자바 스크립트 코드에서

, 나는`document.getElementById를 ('컨테이너 ios9') 생각

   if (window.screen.width <= 400) { 
     var $ios9 = document.getElementById('container-ios9'); 
     var SW9 = new Wave9({ 
           width: 800, 
           height: 40, 
           container: $ios9, 
           }); 
} else { 
//other devices 
     </script> 
관련 문제