gpt4 book ai didi

iphone - UIWebView 在横向 View 右侧加载一些黑屏

转载 作者:行者123 更新时间:2023-11-29 11:06:41 24 4
gpt4 key购买 nike

我正面临这个奇怪的问题,这不是正常行为。我正在从 WebView 中的 url 加载图像。如果我将方向从纵向更改为横向,将横向更改为纵向,没问题。但是在人像中,如果我放大、缩小并双击图像以适合屏幕,然后如果我现在更改为风景,我可以看到右侧出现白/黑屏幕。

我用谷歌搜索了这个问题,我尝试了很多方法,比如不透明属性、透明颜色等。甚至我尝试了自己的方法来解决这个问题,但我失败了。如何解决该问题?

最佳答案

我发布这个是因为我也遇到了同样的问题,我也解决了这个问题,我的代码如下。下面是可以解决问题的完整代码。需要正确地将所有代码放入 View Controller

为此,我设置了捏合手势,以便当用户倾斜 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 不能保证阻止同时识别,因为其他手势的委托(delegate)可能返回 YES

 -(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 View 捏合/捏合,只需设置缩放系数即可。 以便 WebView 可以在 Oreintaion 更改时调整其 ContentSize。

    - (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,这也能完美工作。

关于iphone - UIWebView 在横向 View 右侧加载一些黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com