【问题标题】:UIWebView shifting to the right Xcode 4.6.3UIWebView 向右移动 Xcode 4.6.3
【发布时间】:2013-09-03 03:05:25
【问题描述】:

请帮忙,我在 UIWebView 中有一个 PDF,它向右移动,切断了边框和一些内容。将设备置于横向,然后打开包含 webview/pdf 的页面会导致这种情况发生。这发生在设备和模拟器中。这是代码。

#import "waterTwoViewController.h"

@interface waterTwoViewController ()

@end

@implementation waterTwoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
} 

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.


double screenWidth = [UIScreen mainScreen].bounds.size.width;
double screenHeight = [UIScreen mainScreen].bounds.size.height;

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,   
screenHeight)];

webView.scalesPageToFit=YES;
webView.contentMode = UIViewContentModeScaleToFill;
webView.multipleTouchEnabled = YES;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
UIViewAutoresizingFlexibleHeight;
[self.view addSubview:webView];


NSString *path = [[NSBundle mainBundle] pathForResource:@"WaterLineSizingValues"   
ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];




}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

  • 仅供参考 - 供将来参考 - 不要不必要地删除问题并发布另一个问题只是为了纠正错误。您可以编辑您的问题以更正拼写错误并根据需要添加其他信息。
  • 知道了。我不想让事情变得混乱。

标签: ios xcode pdf uiwebview


【解决方案1】:

为什么要向视图添加两次 UIWebView?

[self.view addSubview:webView];


[self.view addSubview:webView];

好的,试试这个,

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,   
self.view.bounds.size.height)];
webview.backgroundColor = [UIColor redColor]; //check whether webview is the epicenter of the problem
webView.scalesPageToFit=YES;
webView.contentMode = UIViewContentModeScaleToFill;
webView.multipleTouchEnabled = YES;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin; //so that the webview is fixed to the top left corner an expands on all other sides

【讨论】:

  • 不知道为什么我有它,很好。我删除了它,我仍然得到相同的效果。任何人都能够重新创建效果。我发现将设备置于横向然后打开页面会导致这种情况。生病编辑问题。
  • 它似乎解决了这个问题,但现在返回纵向时它会做同样的事情,但我现在可以滚动到剪切区域,但仍然不对。看起来在切换方向时视图正在放大。
  • @Scrappy 您现在应该可以在两个方向上看到穿过碎石的红色。你呢?
  • 是的,它给了我一个红色的背景。去掉第一行,因为 is 已经定义了。我仍然得到相同的效果。我开始认为 UIWebView 不是显示 pdf 的最佳方式。显然我很新。显示存储在支持文件中的 pdf 的标准做法是什么?
  • webview 可以更轻松地加载 PDF 相信我我已经测试过其他方式,它们都是 PIA。
【解决方案2】:

损坏的 PDF 文件导致比例尺适合剪裁边缘。删除并添加回对我有用的项目。

【讨论】:

  • 更正。 @satheeshwaran PDF 很好,仍然没有解决方案。它刚刚开始工作。不知道为什么,所以我做了一些不同的事情,所以不会有任何问题。这是对我更有效的代码 NSString *path = [[NSBundle mainBundle] pathForResource:@"FileName" ofType:@"pdf"]; NSURL *url = [NSURL fileURLWithPath:path]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; //下面的名称(Webview)必须与出口相同 [_webView loadRequest:request]; [_webView setScalesPageToFit:YES];
猜你喜欢
  • 2013-09-27
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-27
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
相关资源
最近更新 更多