iPhone 中单击/触摸时 UIWebView 上的自定义控件覆盖
http://startupmeme.com/wp-content/uploads /2008/09/stanza-on-iphone.png
我想实现像著名的 Stanza 应用程序屏幕截图所示的功能。
内容在 UIWebView 的帮助下以 html 格式显示
单击 UIWebView 将显示两个覆盖控件(顶部和底部)< /p>
底部工具栏由控件和控件组成。用于分页的滑块
请帮忙。
我如何通过以下方式实现上述目标:
如何构建这些自定义控件?
单击时,我将如何覆盖这些控件?
如何组合 UIToolbar(包含控件)和 UIToolbar?滑块?
还需要过渡幻灯片效果,顶部标题来自屏幕顶部,底部控件来自屏幕顶部。滑块来自屏幕底部。我将如何实现这一点?
请帮我详细解答(a)-(d)。一些代码指导会非常有帮助。
谢谢
http://startupmeme.com/wp-content/uploads/2008/09/stanza-on-iphone.png
I want to achieve functionality like the famous Stanza application screenshot shows.
Content is displayed with the help of UIWebView in html format
A single tap on the UIWebView would show two overlay controls (top & bottom)
The bottom toolbar consists of controls & a slider to give pagination
Please help.
How would I achieve the above in following way:
How do i build up these custom controls?
On single tap, how will i overlay these controls?
How do i combine the UIToolbar(which contains controls) & the slider?
Also there is a need of transition slide effect, top header comes from top of screen, bottom control & slider come from bottom of screen. How will i achieve this?
Please help me out elaborately for (a) - (d). Some code guidance would be very helpful.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在做你在我最近一直在做的一个项目中寻找的东西。
基本上,我在 UINavigationController 中有一个 UIWebView,其中有一个 UIToolbar 作为 UIWebView 的同级。我使用 IB 设置所有这些的布局,以创建链接到我的视图控制器类的笔尖。我假设您知道如何使用 IB 以及如何正确设置所有委托、IBOutlet 等,因此这里不再介绍。
您需要在视图控制器中实现适当的委托才能完成所有工作。这是我的视图控制器类的界面:
从技术上讲,您所询问的内容只需要 UIGestureRecognizerDelegate 实现,但我认为您会在 webView 中做一些有趣的事情,因此也想实现 UIWebViewDelegate
我发现实现 UIWebViewDelegate 是至关重要的以下是这三个 UGestureRecognizer 委托方法,因为 UIWebView 也可以识别点击,所以这一切都可以工作:
我在控制器的 viewDidLoad 方法内的 webView 上注册了一个 UITapGestureRecognizer:
这是我的 handleTapFrom 回调:
这个基本框架让我继续前进,希望能回答您的问题或者至少为你指明了正确的方向。
注意:
我还没有处理这样的事实:我可能会将点击解释为“显示/隐藏状态/导航/工具栏”,并且 UIWebView 可能会在同一个点击上充当单击的链接等。我正在计划研究很快……
您在 Stanza 屏幕截图中显示的透明度并不是什么大问题。您必须使用各种导航/工具栏上的 alpha 设置来完成此操作,并更改上面 UIWebView 上的调整大小代码。事实上,我会定期覆盖一个额外的半透明工具栏以用于临时状态、警报等,并且不会调整 UIWebView 的大小,以便它位于下方并且通过此警报工具栏仍然有些可见。
I am doing what you are looking for in a project I've been working on recently.
Basically I have a UIWebView inside of a UINavigationController with a UIToolbar as a sibling to the UIWebView. I setup the layout of all of this using IB to create a nib linked to my view controller class. I presume you know how to use IB and how to correctly setup all of the delegates, IBOutlets, etc. so will not cover that here.
You need to implement the appropriate delegates in your view controller for this to all work. Here is my interface for the view controller class:
Technically what you are asking about only requires the UIGestureRecognizerDelegate implementation but I presume you will be doing something interesting in your webView and thus will want to also implement the UIWebViewDelegate
I found it was critical to implement the following for these three UGestureRecognizer delegate methods to make this all work since the UIWebView is also recognizing taps:
I register a UITapGestureRecognizer on the webView inside my controller's viewDidLoad method:
Here is my handleTapFrom callback:
This basic framework got me going and hopefully answers your question or at least points you in the right direction.
Notes:
I have not yet dealt with the fact that I may interpret a tap as "show/hide the status/nav/toolbars" AND the UIWebView may act on this same tap as a clicked link, etc. I am planning on looking into that shortly…
The transparency you show in the Stanza screen shot is not a big deal. You will have to play with the alpha settings on the various nav/toolbars to accomplish that plus change the resizing code on the UIWebView above. I in fact periodically overlay an additional semi-transparent toolbar for temporary status, alerts, etc and do not resize the UIWebView so that it is underneath and still somewhat visible through this alert toolbar.
bg 清楚地了解 iPhone 机制,所以肯定+1,但我可能知道另一种方式。
将按钮(或视图)叠加到顶部。
根据需要注册一个点击捕捉器(识别器、以 [[事件触摸] tapCount] 或 IB 结束的触摸,或手动操作...基本上抓取点击)。
获得点击后,保存它所在的位置,调用一个函数来通知您的 Web 视图进行分割(或者如果它像节,则表示添加覆盖),然后通过“假装”触摸来通过视图发送触摸,类似对此: 有没有办法传递触摸通过 iPhone?
或创建您自己的目标操作方法并发送它(可能更容易)。
如果您了解 SDK,上面的内容应该对您有意义。特别是视图和所有相关内容(图形除外,您可以跳过该阅读)
bg clearly understands iPhone mechanics, so definitely +1 there, but I might know another way.
Overlay a button (or view) onto the top.
Register a tap catcher however you want (Recognizer, touches ended with [[event touches] tapCount] or IB, or manual action... basically grab the taps).
After you get the tap, save where it was, call a function that notifies your web view to split (or if it's like stanza, says to add the overlay) then literally send the touch through the views by "faking" a touch, similar to this: Is there a way to pass touches through on the iPhone?
or create your own target-action method and send it (probably easier).
If you understand the SDK, the above should make sense to you. Specifically the views and everything related (except the graphics, you can skip that reading)