【问题标题】:iPhone WebApp QuestioniPhone WebApp 问题
【发布时间】:2011-02-23 12:46:04
【问题描述】:

我有这个代码-

/** 将 Web 视图另存为屏幕截图。目前只支持保存到 照片库。 / - (void)saveScreenshot:(NSArray)arguments with Dict:(NSDictionary*)options { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGRect imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect));

UIGraphicsBeginImageContext(imageRect.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, self, nil, nil);

UIAlertView *alert= [[UIAlertView alloc] initWithTitle:nil

消息:@“图像已保存”委托:self cancelButtonTitle:@“确定” 其他按钮标题:无]; [警报显示]; [警报发布];

}

这是为了保存您在我的应用中绘制的任何内容。我将如何在 HTML 代码中为此添加按钮。我如何调用它?

【问题讨论】:

    标签: javascript iphone objective-c


    【解决方案1】:

    所以你正试图从 html 向 UIWebView 发送事件?

    最简单的方法是使用私有方案。在html中:

    <a href="myscheme:save_picture">Take Picture</a>
    

    在 UIWebView 委托中:

    -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
        NSString    *string = [[[inRequest URL] absoluteString] lowercaseString];
        if ( [string isEqualToString:@"myscheme:save_picture"] ) {
            [self savePicture];
            return NO;
        }
        return YES;
    }
    

    您可以查看PhoneGap 以更可靠地使用此机制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多