2014-09-15 33 views
5

UIWebview kullanıyorum, ancak ios8'de web görünümünün arkasında siyah bir arka plan var. Aynı şey ios7'de gayet iyi çalışıyor. Ayrıca NO'ya opak ayarlıyorum.UIWebView ios8 saydam arka plan

+0

Aynı soru burada: http://stackoverflow.com/questions/25813551/rendering-pdf-in-uiwebview-ios-8-causes-a-black-border-around-pdf – Boris

cevap

-1
Put a instance variable in the in the header file or your class: 

// instance variable for interval timer 
NSTimer *BackgroundIntervalTimer; 
Put these methods in the implementation file: 

- (void)startUIWebViewBackgroundFixTimer { 
    // if > iOS 8 start fixing background color of UIWebPDFView 
    if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) { 
     // hide pdfWebView until background fixed 
     self.pdfWebView.alpha = 0.0; 
     // start interval timer 
     BackgroundIntervalTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fixBackground) userInfo:nil repeats:YES]; 
    } 
} 

- (void)stopUIWebViewBackgroundFixTimer { 
    [BackgroundIntervalTimer invalidate]; 
    BackgroundIntervalTimer = nil; 
} 

- (void)fixBackground { 
    // stop timer interval 
    [self stopUIWebViewBackgroundFixTimer]; 

    // Assuming self.webView is our UIWebView 
    // We go though all sub views of the UIWebView and set their backgroundColor to white 
    UIView *v = self.pdfWebView; 
    while (v) { 
     //v.backgroundColor = [UIColor whiteColor]; 
     v = [v.subviews firstObject]; 

     if ([NSStringFromClass([v class]) isEqualToString:@"UIWebPDFView"]) { 
      [v setBackgroundColor:[UIColor whiteColor]]; 

      // background set to white so fade view in and exit 
      [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseOut 
          animations:^{ 
           self.pdfWebView.alpha = 1.0; 
          } 
          completion:nil]; 
      return; 
     } 
    } 
    // UIWebPDFView doesnt exist yet so exit and try later 
    [self startUIWebViewBackgroundFixTimer]; 
} 
Now put this line right after the line where you load the pdf: 

// if iOS 8 check if pdfWebView got subview of class UIWebPDFView 
[self startUIWebViewBackgroundFixTimer]; 
0

UIWebview'i programa göre alt görünüm olarak eklemeyi deneyin.

WebView = [[UIWebView alloc]initWithFrame:CGRectMake(264, 10, 745, 576)]; 
    WebView.userInteractionEnabled = YES; 
    [self setBorderToView: WebView]; 
    WebView.scrollView.bounces = NO; 
    [WebView setBackgroundColor:[UIColor clearColor]]; 
    [WebView setOpaque:NO]; 
    [WebView loadHTMLString: embedHTML baseURL: nil]; 
    [self.view addSubview: WebView]; 

Bu yardımcı olur umarım!

0

Aynı sorunu da çözdüm, uygun bir çözüm bulamadıktan sonra Masking kullanarak bir numara yaptım.

 CALayer *aLayer = [CALayer layer]; 
     aLayer.backgroundColor = [UIColor blackColor].CGColor; 
     aLayer.frame = CGRectMake(origin.x, origin.y, widthOfVideo, heightOfVideo); 
     objWebView.layer.mask = aLayer; 

Ve bu benim için çalıştı. Umarım size yardımcı olabilir.

İlgili konular