从 InAppBrowser 旋转 PDF
Posted
技术标签:
【中文标题】从 InAppBrowser 旋转 PDF【英文标题】:Rotate a PDF from InAppBrowser 【发布时间】:2013-08-26 18:11:58 【问题描述】:所以我能够集成InAppBrowser-CE 这个插件,它可以从指定的窗口大小显示 PDF 并提供透明度,但现在我想弄清楚如何旋转 PDF。我想添加一个旋转工具(类似于 ios 中的照片库),但不知道从哪里开始。我看到了一些关于图像旋转工具的东西,但不确定它是否适用于 pdf 文件,并且我不想保留一些不起作用的东西(即使用 iFrame 而不是 InAppBrowser 来显示 PDF)任何帮助非常感谢.这里只是一个如何调用 PDF 的示例,以便为您提供一些见解。
这是从html中调用它打开的:
<button onclick="window.open('http://www.free.woodworking-plans.org/images/ranch-house-7161/ranch-house-floor-plan-o.jpg','_blank','vw=685,vh=650,vx=40,vy=40');">Change my size</button>
这是打开 PDF 的方式(来自 xcode CDVInAppBrowser.m)
- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
if (self.inAppBrowserViewController == nil)
NSString* originalUA = [CDVUserAgentUtil originalUserAgent];
self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA prevUserAgent:[self.commandDelegate userAgent]];
self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)])
self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
// set pointer to this viewcontroller for later use
iabvc = self.inAppBrowserViewController;
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar];
....
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent
self = [super init];
if (self != nil)
_userAgent = userAgent;
_prevUserAgent = prevUserAgent;
_webViewDelegate = [[CDVWebViewDelegate alloc] initWithDelegate:self];
[self createViews];
return self;
这里是工具部分的样子,
self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, (self.view.bounds.size.height - TOOLBAR_HEIGHT), self.view.bounds.size.width, TOOLBAR_HEIGHT)];
self.toolbar.alpha = 1.000;
self.toolbar.autoresizesSubviews = YES;
self.toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self.toolbar.barStyle = UIBarStyleBlackOpaque;
self.toolbar.clearsContextBeforeDrawing = NO;
self.toolbar.clipsToBounds = NO;
self.toolbar.contentMode = UIViewContentModeScaleToFill;
self.toolbar.contentStretch = CGRectFromString(@"0, 0, 1, 1");
self.toolbar.hidden = NO;
self.toolbar.multipleTouchEnabled = NO;
self.toolbar.opaque = NO;
self.toolbar.userInteractionEnabled = YES;
【问题讨论】:
【参考方案1】:我创建了一个旋转按钮,然后在下面添加了这个,
.h
//header - add 'int counter'
@interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate>
@private
NSString* _userAgent;
NSString* _prevUserAgent;
NSInteger _userAgentLockToken;
CDVWebViewDelegate* _webViewDelegate;
int counter;
.m
//Add this to the top of the .m file
#define DegreesToRadians(X) ((X) * M_PI / 180.0)
...
//reference
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent
counter = 0;
...
//create Rotate Button
NSString* rotateString = @"Rotate";
self.RotateButton = [[UIBarButtonItem alloc] initWithTitle:rotateString style:UIBarButtonItemStylePlain target:self action:@selector(goRotate:)];
self.RotateButton.enabled = YES;
self.RotateButton.imageInsets = UIEdgeInsetsZero;
....
//action - sender
-(IBAction)goRotate:(id)sender
counter ++; float angle = (counter%3)*90;
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:0.5];
self.webView.transform = CGAffineTransformMakeRotation(DegreesToRadians(angle));
[UIView commitAnimations];
【讨论】:
以上是关于从 InAppBrowser 旋转 PDF的主要内容,如果未能解决你的问题,请参考以下文章
Cordova 无法从 InAppBrowser 调用自定义 URL 方案到同一应用程序
执行从InAppBrowser中的executeScript调用的typescript函数
从 InAppBrowser IONIC 5 获取 JSON 数据
Cordova inAppBrowser 如何隐藏 URL 并仅显示完成按钮