2013-04-24 2 views
2

질문이 있습니다. Xcode에는 ViewController이 포함 된보기>ScrollView이고 Scrollview 내부는 UIWebView입니다.iOS : UIWebView의 높이 조절 - 이상한 행동

응용 프로그램에서 일부 XML 데이터를 읽고 형식이 지정된 텍스트를 UIWebView에 붙여 넣습니다. UIWebView-Element이 다른 요소이기 때문에 동적으로 UIWebView의 높이를 조정해야합니다.

보기를로드 한 후에도 문제가 없지만 화면을 두 드릴 때보기의 크기는 scrollview의 스토리 보드 높이가됩니다.

왜? 당신이 프레임을 변경 때마다

- (void)webViewDidFinishLoad:(UIWebView *)aWebView 
{ 
aWebView.scrollView.scrollEnabled = NO; // Property available in iOS 5.0 and later 
CGRect frame = aWebView.frame; 

frame.size.width = 280;  // Your desired width here. 
frame.size.height = 1;  // Set the height to a small one. 

aWebView.frame = frame;  // Set webView's Frame, forcing the Layout of its embedded  scrollView with current Frame's constraints (Width set above). 

frame.size.height = aWebView.scrollView.contentSize.height; // Get the corresponding   height from the webView's embedded scrollView. 

aWebView.frame = frame;  // Set the scrollView contentHeight back to the frame itself. 

NSLog(@"size: %f, %f", aWebView.frame.size.width, aWebView.frame.size.height); 

// Position URL Label 
CGRect frame_label = fachmesseDetailWebsite.frame; 
NSLog(@"x: %f", frame_label.origin.x); 
NSLog(@"y: %f", frame_label.origin.y); 
frame_label.origin.y=aWebView.frame.size.height+115;//pass the cordinate which you want 
frame_label.origin.x= 20;//pass the cordinate which you want 
fachmesseDetailWebsite.frame= frame_label; 
NSLog(@"x: %f", frame_label.origin.x); 
NSLog(@"y: %f", frame_label.origin.y); 

} 

답변

1

당신 만 웹뷰 프레임이 다른 현명한는 웹보기에 거기에 영향을주지 않는 넣어 어떤 변경됩니다 웹보기를 다시로드해야합니다.

[webview reload]; 

편집 :

UIWebView *web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; 

    NSString* html = [NSString stringWithFormat:@"<html><head><style>a { color: #db5226; text-decoration: none; font-weight: bold; } body { padding: 0; margin: 0; font-size:45px;font-family: Helvetica;text-align:left; color:black; } </style></head<body>%@</body></html>",@"helow"]; 
    [web loadHTMLString:html baseURL:nil]; 
    [self.view addSubview:web]; 
+0

감사 작업이 하나. 다음은 웹 뷰에 콘텐츠를 추가하는 방법입니다. NSString * html = [NSString stringWithFormat : @ " % @ ", item.description]; [self.fachmesseDetailText loadHTMLString : html baseURL : nil]; ' webview를 새로 고침하면 everythink가 비어 있습니다 ... –

+0

이 자습서 참조 http://www.roseindia.net/answers/viewqa/Mobile-Applications/16673 -UIWebview-load-url.html – Balu

+0

한번 확인하십시오 .. – Balu