我正面临这个奇怪的问题,而不是正常行为。我正在从 web 视图中的 url 加载图像。如果我将方向从纵向更改为横向,将横向更改为纵向,则没有问题。但是在纵向如果我进行一些放大、缩小并双击图像以适应屏幕,那么如果我现在更改为横向,我可以看到右侧出现白色/黑色屏幕。
我已经用谷歌搜索过这个问题,我尝试了很多方法,比如不透明属性、清晰颜色等。即使我尝试了自己的方法来解决这个问题,但我失败了。如何解决问题?
我正面临这个奇怪的问题,而不是正常行为。我正在从 web 视图中的 url 加载图像。如果我将方向从纵向更改为横向,将横向更改为纵向,则没有问题。但是在纵向如果我进行一些放大、缩小并双击图像以适应屏幕,那么如果我现在更改为横向,我可以看到右侧出现白色/黑色屏幕。
我已经用谷歌搜索过这个问题,我尝试了很多方法,比如不透明属性、清晰颜色等。即使我尝试了自己的方法来解决这个问题,但我失败了。如何解决问题?
我发布这个是因为我也遇到了同样的问题,我也解决了这个问题,我的代码如下。下面是可以解决问题的整个代码。需要正确放入所有代码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 会阻止同时识别,因为其他手势的代表可能会返回 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 视图,只需设置 THat Zooming Factor 。这样 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 也非常有效。