2012-11-09 24 views
1

我不会面临这个奇怪的问题,在一个正常的行为。我从网络视图中的url中加载图像。如果我将方向从纵向改为横向,风景改为纵向没问题。但是在人像中如果我做一些放大,缩小和双击图像以适应屏幕,那么如果我现在更改为风景,我可以看到白色/黑色屏幕在右侧。UIWebView的景观右侧装载一些黑色的屏幕查看

我用Google搜索这个问题,我尝试过很多办法像不透明的财产,鲜明的色彩等。即使我想我自己的方式来解决这个问题,但我失败了。如何解决这个问题?

+0

哎'Cyril'这是因为破天作为内容不调整properly.so你需要你重新调整的UIWebView的ContentSIze。请参阅下面的我的答案。在我的答案中仔细查看我的答案我已照顾到每个方面。 – Kamarshad

+0

雅@Kamarshad。我只检查您的代码。我会让你知道 – Cyril

回答

2

我发布这个,因为我也面临同样的问题,我也修复了这个问题,我的代码如下。以下是可以解决问题的整个代码。需要将ALl代码正确放入ViewControler

为此,我设置缩放手势,这样当用户歪曲UIwebView可以检查UIwebView.

 //One This Please import The `UIGestureRecognizerDelegate` Protocol in '.h file' 

    //call below method in ViewDidLoad Method for setting the Pinch gesture 

    - (void)setPinchgesture 
    { 
    UIPinchGestureRecognizer * pinchgesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(didPinchWebView:)]; 

    [pinchgesture setDelegate:self]; 

    [htmlWebView addGestureRecognizer:pinchgesture]; 
    [pinchgesture release]; 
    // here htmlWebView is WebView user zoomingIn/Out 

    } 

//Allow The allow simultaneous recognition 

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
    { 
    return YES; 
    } 

返回YES的缩放尺寸是保证允许同时识别。返回NO不能保证防止同时承认,与其他姿势的代表可能是

-(void)didPinchWebView:(UIPinchGestureRecognizer*)gestsure 
    { 
    //check if the Scaled Fator is same is normal scaling factor the allow set Flag True. 
    if(gestsure.scale<=1.0) 
    { 
    isPinchOut = TRUE; 

    } 
    else// otherwise Set false 
    { 
    isPinchOut = FALSE; 
    } 
    NSLog(@"Hello Pinch %f",gestsure.scale); 
    } 

返回如果用户长谷捏/输出在这种情况下,Web视图只需设置变焦系数。 因此WebView可以调整其ContentSize为Oreintaion更改。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    //Allow the Execution of below code when user has Skewed the UIWebView and Adjust the Content Size of UiwebView. 

    if(isPinchOut){ 
    CGFloat ratioAspect = htmlWebView.bounds.size.width/htmlWebView.bounds.size.height; 
    switch (toInterfaceOrientation) { 
    case UIInterfaceOrientationPortraitUpsideDown: 
    case UIInterfaceOrientationPortrait: 
     // Going to Portrait mode 
     for (UIScrollView *scroll in [htmlWebView subviews]) { //we get the scrollview 
      // Make sure it really is a scroll view and reset the zoom scale. 
      if ([scroll respondsToSelector:@selector(setZoomScale:)]){ 
       scroll.minimumZoomScale = scroll.minimumZoomScale/ratioAspect; 
       scroll.maximumZoomScale = scroll.maximumZoomScale/ratioAspect; 
       [scroll setZoomScale:(scroll.zoomScale/ratioAspect) animated:YES]; 
      } 
     } 
     break; 

    default: 
     // Going to Landscape mode 
     for (UIScrollView *scroll in [htmlWebView subviews]) { //we get the scrollview 
      // Make sure it really is a scroll view and reset the zoom scale. 
      if ([scroll respondsToSelector:@selector(setZoomScale:)]){ 
       scroll.minimumZoomScale = scroll.minimumZoomScale *ratioAspect; 
       scroll.maximumZoomScale = scroll.maximumZoomScale *ratioAspect; 
       [scroll setZoomScale:(scroll.zoomScale*ratioAspect) animated:YES]; 
      } 
     } 
     break; 
    } 
    } 

    } 

这适用于甚至用户倾斜UIWebView。

+0

谢谢你Kamarshad。代码工作正常。但是你知道,黑屏问题出现在捏合和捏合中。所以我会在识别捏手势时使布尔变量为真。再次感谢 – Cyril

+0

@Cyril我确信此代码工作正常,您只需要清楚地将此代码。当您倾斜WebView和您同时更改设备方向时,此空白SCreen基本显示。 – Kamarshad