2013-10-22 1 views
2

현재 OS X 10.6과 호환되는 OS X 용 응용 프로그램을 개발 중입니다. 어떤 시점에서 나는 내가 동적으로 생성하는 HTML 컨텐트를로드하는 WebView를 작성합니다. html 콘텐츠는 이미지 링크 <img src=과 텍스트로만 구성되며 자바 스크립트 나 그 종류의 것이 없습니다. 모든 이미지 (5 개의 PNG 이미지 만 있음)는 로컬에 저장되며 크기는 4KB입니다.코코아 WebView가 OSX 10.8의 모든 이미지를 렌더링하지 않습니다.

내가 가진 문제는 창을 다른 화면으로 드래그하지 않으면 일부 이미지 ("스크롤"의 눈에 보이지 않는 부분), 애플리케이션을 처음 실행했을 때 이미지가 표시되지 않는다는 것입니다. 또는 WebView가 포함 된보기 컨트롤러를 다시로드하십시오. 이 경우 이미지는 오프 사이트 인 경우에도 "스크롤"에 표시됩니다.

IB로 ​​프로그래밍 방식으로 WebView를 만들려고했는데 Autosaves, AllowsAnimatedImages와 같은 WebPreferences를 사용했습니다 ... WebView가 더 쉽게 액세스 할 수 있도록 NSURLCache를 사용하여 각 이미지를로드하려고했습니다 ... 같은 결과.

NSString *finalHtml ... //contains the complete html 


CGRect screenRect = [self.fixedView bounds]; 
CGRect webFrame = CGRectMake(0.0f, 0.0f, screenRect.size.width, screenRect.size.height); 

self.miwebView=[[WebView alloc] initWithFrame:webFrame]; 
[self.miwebView setEditable:NO]; 
[self.miwebView setUIDelegate:self]; 
[self.miwebView setResourceLoadDelegate:self]; 
[self.miwebView setFrameLoadDelegate:self]; 

WebPreferences *webPref = [[WebPreferences alloc]init]; 
[webPref setAutosaves:YES]; 
[webPref setAllowsAnimatedImages:YES]; 
[webPref setAllowsAnimatedImageLooping:YES]; 
[self.miwebView setPreferences:webPref]; 


    ... 

NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 
                     diskCapacity:20 * 1024 * 1024 
                      diskPath:nil]; 
[NSURLCache setSharedURLCache:URLCache]; 
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"line" ofType:@"png"]; 
NSURL *resourceUrl = [NSURL URLWithString:imagePath]; 
NSURLRequest *request = [NSURLRequest requestWithURL:resourceUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f];   
[URLCache cachedResponseForRequest:request]; 

     ... 

NSString *pathResult = [[NSBundle mainBundle] bundlePath]; 
NSURL *baseURLRes = [NSURL fileURLWithPath:pathResult]; 

[[self.miwebView mainFrame] loadHTMLString:finalHtml baseURL:baseURLRes]; 
[self.fixedView addSubview:self.miwebView]; 

나는 또한 언급해야 그 이미지가 보이는 사이 어딘가에 잡힌 경우 :

내가 생각하는 관련 만 비트를 거 포스트 해요 내 코드는 매우 광범위 고려하여 "스크롤"의 보이지 않는 부분은 페이지가 스크롤되는 경우에도 이미지의 보이는 비트 만 렌더링 될 것입니다 ... 그래서이 모든 렌더링 문제가 있다고 생각합니다 ...

감사합니다. , 고맙습니다!

+0

나는이 문제가 OS에서 X 10.7에만 10.8에서 일어나는 존재하지 않는 것을 추가해야합니다 – Artur

답변

0

Ok 사람들 나는 문제가 무엇인지 알아 냈습니다. 웹뷰 내용은 웹뷰 프레임 안에서 렌더링되었지만 프레임은 문서보다 작았습니다. didFinishLoadForFrame : 그래서 웹보기에 다음 코드 조각을 추가하여 문제를 해결 한

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 
{ 
    //Get the rect for the rendered frame 
    NSRect webFrameRect = [[[[miwebView mainFrame] frameView] documentView] frame]; 
    //Get the rect of the current webview 
    NSRect webViewRect = [miwebView frame]; 
    //Calculate the new frame 
    NSRect newWebViewRect = NSMakeRect(webViewRect.origin.x, 
              webViewRect.origin.y - (NSHeight(webFrameRect) - NSHeight(webViewRect)), 
              NSWidth(webViewRect), 
              NSHeight(webFrameRect)); 

    [miwebView setFrame:newWebViewRect]; 
    [miwebView setFrame:webViewRect]; 
    [[[miwebView mainFrame] frameView] setAllowsScrolling:YES]; 
} 
관련 문제