- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我现在正在编写一个应用程序,它可以从我的服务器加载文章列表和特定文章。我正在使用 UIWebView 加载文章内容(女巫是一个 HTML 字符串)。现在的问题是,当用户按住 UIWebView 中的图像时,会跳出一个操作表并为用户提供保存图像 选项。
这些我都试过了,但都不适合我。
stackoverflow.com/questions/31522037/tap-and-hold-to-save-image-in-uiwebview
stackoverflow.com/questions/31673916/tap-and-hold-save-image-from-uiwebview
buzztouch.com/forum/thread.php?tid=7EF2CABD19B91FB8D9C20E6¤tPage=1
最佳答案
是的!!!!!!!我终于做到了!!!!通过使用 JavaScript 和 stringByEvaluatingJavaScriptFromString
。
我在 github 上发布了我的答案:https://github.com/theniceboy/HoldToSaveImage
这是我的代码:
//
// FrmArticle.swift
// CenterBrain
//
// Created by David Chen on 9/7/15.
// Copyright © 2015 David Chen. All rights reserved.
//
import UIKit
class FrmArticle: UIViewController, UIWebViewDelegate {
// MARK: - Outlets
@IBOutlet weak var wvContent: UIWebView!
// MARK: - Vars & Lets
var article_id: Int = 1
var article: Article = Article()
let kTouchJavaScriptString: String = "document.ontouchstart=function(event){x=event.targetTouches[0].clientX;y=event.targetTouches[0].clientY;document.location=\"myweb:touch:start:\"+x+\":\"+y;};document.ontouchmove=function(event){x=event.targetTouches[0].clientX;y=event.targetTouches[0].clientY;document.location=\"myweb:touch:move:\"+x+\":\"+y;};document.ontouchcancel=function(event){document.location=\"myweb:touch:cancel\";};document.ontouchend=function(event){document.location=\"myweb:touch:end\";};"
var _gesState: Int = 0
/*
_gesState:
GESTURE_STATE_NONE = 0,
GESTURE_STATE_START = 1,
GESTURE_STATE_MOVE = 2,
GESTURE_STATE_END = 4
*/
var _imgURL: String = "", _timer: NSTimer = NSTimer()
func webView(webView: UIWebView, shouldStartLoadWithRequest _request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if (_request.URL! == "about:blank") {
return false
}
let requestString: String = (_request.URL?.absoluteString)!
var components: [String] = requestString.componentsSeparatedByString(":")
if (components.count > 1 && components[0] == "myweb") {
if (components[1] == "touch") {
if (components[2] == "start") {
_gesState = 1
print("touch start!")
let ptX: Float = Float(components[3])!
let ptY: Float = Float(components[4])!
print("touch point \(ptX), \(ptY)")
let js: String = "document.elementFromPoint(\(ptX), \(ptY)).tagName"
let tagName: String = wvContent.stringByEvaluatingJavaScriptFromString(js)!
_imgURL = ""
print(tagName)
if (tagName == "IMG") {
_imgURL = wvContent.stringByEvaluatingJavaScriptFromString("document.elementFromPoint(\(ptX), \(ptY)).src")!
_timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "handleLongTouch", userInfo: nil, repeats: false)
}
} else {
if (components[2] == "move") {
self._gesState = 2
print("you are move")
} else {
if (components[2] == "end") {
_timer.invalidate()
self._timer = NSTimer()
self._gesState = 4
print("touch end")
}
}
}
}
return false
}
return true
}
func handleLongTouch() {
print(_imgURL)
if (_gesState == 1) {
print("YES!!! I DID IT!!!")
}
}
// MARK: - Override functions
override func viewDidLoad() {
wvContent.delegate = self
super.viewDidLoad()
wvContent.loadHTMLString("<h2 align=\"center\">Title</h2><img src=\"http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=ea71a5211a91&a\">", baseURL: nil)
}
// MARK: - UIWebView delegate
func webViewDidFinishLoad(webView: UIWebView) {
activityIndicator.stopAnimating()
activityIndicator.hidden = true
wvContent.stringByEvaluatingJavaScriptFromString(kTouchJavaScriptString)
}
}
关于ios - swift/iOS |如何启用 'press and hold' 以在 UIWebView 中保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32435194/
我在按下按钮后制作了一个扩展表单,但现在我也想添加 Enter 按键,但我不知道如何操作。也许有人可以帮助我!? 代码 $(document).ready( function() {
基本上我使用的是 z-index,通过单击按钮,它应该拍摄背面照片并将其置于正面,反之亦然。我目前正试图让按钮正常工作。 Lab 5, Part 1
这个问题已经有答案了: AlertDialog OnBackPressed() Not Working Properly (3 个回答) 已关闭 4 年前。 我想实现抽屉导航后按对话框上的对话框后按。
我有一个点击功能,长按同一个按钮。实现了长按事件,但我需要分别找到按钮 UP_EVENT 和 DOWN_EVENTS。如何使用 OnLongClickListener 实现 View.OnLongC
我需要简单地检测每时每刻在我的 Qt5/C++ 应用程序中何时按下或释放右键。 到目前为止,我已经编写了这些函数: void test::mousePressEvent(QMouseEvent *ev
我有一个输入框和它下面的“添加”按钮。添加按钮基本上所做的是,它将一个新的输入字段附加到文档中。我在这里尝试做的是,在输入字段中键入时,如果检测到返回键按下,调用添加新输入字段的函数将被触发,与单击添
我正在使用 Java swing 和 Matlab 开发一个项目。我有一个带有 2 个按钮“运行”和“暂停”的 GUI。我正在使用另外一个 java 程序 (Matlabjavaprog.java),
目前,我有一个带有 9 补丁图像作为边框的自定义 View 。 该自定义 View 在 LinearLayout 中放置了三次,所以它看起来像这样: +------------------------
我正打算用一个 TButtonedEdit 控件替换 TEdit + TButton 组合,但当我尝试测试它时,我发现无法使用键盘“按下”(右)按钮。 我尝试了 Alt+Enter、Alt+Down、
您好,我在模糊()和回车键上执行相同的代码时遇到了一些麻烦。我使用以下代码: $(".formatted-date").bind('blur keyup',function(e) { if
这是一个关于android java编程的一般问题。 有没有办法(当手机锁定时)检测是否按下主页按钮几秒钟? 最佳答案 由于不需要硬件按钮,因此并非所有手机都可以使用主页。 关于java - 手机锁定
我在 Pane 中有一个 ImageView,并且该 Pane 已设置 MouseEventHandler 来执行一些操作。 ImageView 的图像在 CSS 文件中定义如下: .imageVie
我需要以编程方式从交互功能内部按下一个键。以下是我目前所掌握的内容的概要: (defun answer-to-life-the-universe-and-everything () (intera
我正在尝试做一个简单的选择器。 这是我的选择器 xml 代码,名为“butt.xml”: 这就是布局: 这就是代码: ImageButton ib; @Override public vo
基本上我是在调用 API 来检索慈善机构列表。然后我将所有这些放在一个数组中并动态设置 UIButtons。 然后我允许用户选择慈善机构并显示包含该索引数据的 View 。 我的循环在这里; for
让我解释更多细节。 首先;我知道如果用户按回键并返回上一个 Activity ,则上一个 Activity 会正确触发 onResume 方法。这没关系。 我的应用程序中有一个根 Activity ,
我正在使用 BootStrap Group Button 类,发现在我自己的代码中,如果按下一个按钮,该按钮将在几秒钟后弹出.... 如何确保它保持按下状态? Stage
我有一个 ListView,当通过 onItemClick 监听器单击项目行时,它会打开另一个 Activity 。 我希望该行从被点击到屏幕切换到新 Activity 时一直保持按下状态。我认为这对
我正在使用 Hammer.JS 来检查事件。我想长按做一些事情。所以我正在使用像这样的锤子新闻事件 var mc = new Hammer(can); mc.on("press", function
我构建了一个 Swing GUI 应用程序,除了一些细节之外,一切都运行良好:我有两个按钮,每个按钮都附加了一个鼠标单击事件。问题是,当我单击它们时,它们保持“按下”状态:其他一切都正常,但看到这两个
我是一名优秀的程序员,十分优秀!