I'd like to add a header view to an UIWebView
similar to the address/search bar in MobileSafari and the excellent Articles.app by Sophia Teutschler. More precisely, I'd like to create a "pull to fix orientation" view above a UIWebView, just like in Articles. Articles does use a UIWebView, so it seems to be possible. Is there a way to accomplish this without having to embed the UIWebView
into a UIScrollView
and updating its size all the time, as described in this article? Apparently, I do need the scrolling events to have the "pull to fix orientation" behave accordingly.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
I like AutoLayout specially because I can make the height of the header dynamic.
This is my code using AutoLayout in a controller with a reference 'headerView' to the header view and a 'webView' to the webView.
I think the best solution is to add the header as a subview of your UIWebView’s scrollView, adjust UIEdgeInsets, and in the scrollViewDidScroll delegate function adjust the scrollIndicatorInsets as needed.
Every other solution I found didn't account for the scroll indicators.
Since getting the behavior just right has a bit of complexity to it, I decided to write a class to handle all of it: MMWebViewWithSmartHeader. It's still a little rough around the edges but should help.
Enormego published some sample code to make the pull-to-refresh thing happen:
https://github.com/enormego/EGOTableViewPullRefresh
It's really not so complicated. You can get a Safari/Articles-style header bar in your table view simply by creating your header bar and just adding it to your
UITableView
as a subview. I'm doing exactly that on the app I'm working on now:The tricky part is observing the scroll events on the table (FYI, UITableView is a subclass of UIScrollView so all the same notifications/callbacks should work), but the sample code I linked to has a good example of how that works.
After several attemps, I've decided to go with this solution:
Basically I've just added my header UIView as a webview.scrollview subview.
To avoid having the header overlap the browser view:
change its origin.y
here's the code:
Articles may not be using a UIWebView to display the main article text. To accomplish your task, UIScrollView will be required almost certainly. Resizing its subviews may not be necessary. Check out the UIScrollView code samples provided by Apple.
I could not say for sure, but Twitter seems to use
UITableView
to achieve this. Perhaps you can try to put your view in the header of the table view, and your content in a cell.Here is an interesting example you might consider looking at - How to make a Pull-To-Reload TableView just like Tweetie 2