I'd need to create a iPad-app which would be rendering multiple PDF-Files (one file contains one page).
Each page should be scrollable, zoomable and if the user taps on a part of the PDF a website or photo gallery should popup.
Currently i think i could do that either with:
A. UIWebView
Displays the pdf's nicely, scrolling and zooming works. But it looks like a lot of trouble to realize the clickable parts of the PDF.
I don't know if i could use CGPDFContextSetURLForRect
Getting the touch-events from UIWebView to do something like CGPDFContextSetURLForRect my self looks like it would be some "quite bad" hack. See: http://github.com/psychs/iphone-samples/blob/master/WebViewTappingHack/Classes/PSWebView.m
B. Quartz
I found some resources describing how to display PDF's directly via Quartz.
See:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
This would allow using CGPDFContextSetURLForRect
But i have no idea if this would - like UIWebView - support scrolling and zooming out of the box?
Anybody could enlighten me on this please?
Thanks for your time!
[Edit: changed 3.0 to 3.2]
[Edit: my "solution"]
Hi!
I could come up with a working implementation for PNG but not for PDF's.
[Abstract]
My sollution was Rendering the content, intercepting the touches on it, retreiving the coordinates relative to the displayed content if it is one touch and finally looking up what to do from a mapping containing the interactive areas as coordinates and what to do if they get clicked.
[For PNG]
It was way more cumbersome to implement somethink like that than i would have imagined...
And the implementation i got working depends heavily on the content you want to display because this does work for UIImageView but i could not get it working with UIWebView.
First you need a UIScrollView and UIImageView to render the content and support scrolling/zooming.
Then you need to implement some handling to get the touches/gestures you are interested in.
See: developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Listings/1_TapToZoom_Classes_TapDetectingImageView_h.html
This sample from apple provides everything you need to get this part working.
As a bonus it also takes care about transforming the coordinates relative to the viewport of the content which is very handy! (else you would only know where the tap happend on the screen wich only one half of the info you need if your content is zoom-/scrollable)
[For PDF]
If you want to do this with PDF the first thing would be that you need to use a UIWebView (probably you could do it via Quartz or something else too)
Getting the touches with a UIWebView is a real pain!
There are a lot of ways proposed on the web and besides one noone did what it should do.
After days of googling i found this gem: cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
So... subclassing UIWebView does not get you anywhere unlike UIImageView and you have to subclass UIApplicationMain and implement its method for handling touch-events.
Here you could reuse some of the "Touch-Handling-Stuff" from the apple-examlpe from above.
Now you would need to translate the coordinates of the touch to your content if it is zoom-/scrollable. UIWebView DOES NOT do this for you unlike UIImageView!
I could never figure out how to get the required information(what part of the content at which zoomlevel) from a UIWebView to translate the coordinates but due to the changed requirements from PDF to PNG i didn't care to get it working too much.
hope this helps.
Using the CGPDF* operators will allow you to write a UIPDFView, which operates exactly as UIImageView but uses a PDF as the source image. Create your own custom subclass of UIView and implement drawRect: to, eventually, call CGContextDrawPDFPage. Based on a quick Google search (because I know the keywords), this page seems to explain that side of things quite well.
You can then directly substitute your custom UIView subclass for the UIImageView and proceed exactly as you have with the PNG solution.
Related
I am trying to code a "webpage selector" on my app, using a fancy carousel to display the webpages thumbnails.
However, I don't want to display the webpages thumbnails as webViews on my carousel because I can get quite a large number (20-30) of webpages at the same time and loading all of those can cause a lot of lag.
So, I decided to use screenshots of the webpages and use those images to populate my carousel instead, making the carousel animation much smoother.
Here is my question:
I would like to know if there is any way to take a screenshot of the webpage (without showing it on the app screen) and save the image into a list that I can use to populate the carousel.
I am aware of this question but is quite an old post, so I was wondering if there is another way to do it. Also, I tried to implement the suggested solution, but it did not work.
You can create a WKWebView that is behind your view controller (and thus invisible) and constrained to the size that you want. Once the page finishes loading take a snapshot by using drawHierarchy(in:afterScreenUpdates:) inside of a UIGraphicsImageRender and save the resulting image as your thumbnail.
I'm looking for a way to draw "Lines" above a UIWebView.
I have a UIWebView that display a PDF file, the user should be able to add "Lines" and "Sketches" (simple one color lines etc) for sure this could be done with a UIView on top of the UIWebView but i m running into 2 logical problems.
First can the UIView where the drawing is, be transparent beside the lines - so you can view the pdf through it?
How could i handle the zooming in the PDF, if a user zoom the WebView, the UIView have to zoom "with each other" - so the drawing stays at the same spot/zoom level?
Is there any other way to display a PDF and add drawings/annotations to it? Currently i m using a QLPreviewController where i see no way to add any kind of annotations?
Is three any best practice for this?
PSPDFKit handles this (and many other hard PDF problems) very well. Using a web view for this kind of problem is likely to have many little corner cases. Any commercial product that has non-trivial needs around PDFs should definitely start there. For open source projects I don't have a great answer beyond "yeah, PDFs are a pretty tough; good luck."
That said, here are some starting points that may help you.
You can turn off zooming with webView.scalesPageToFit = false
You can get the current zoom scale using webView.scrollView.zoomScale
I believe you can KVO observe zoomScale to track it while it changes, but you may only get the target value (which will cause you to lag).
You can disable zooming (scalesPageToFit) and then re-implement it yourself with a UIPinchGestureRecognizer and scrollView.setZoomScale(_:animated:). That way you could track the zoom changes better. You could also try to handle the animation yourself with a CABasicAnimation so that you could keep it in sync.
My experience with scroll views, web views, and PDF is that there are a lot of little funny interactions that will surprise you. Getting something that "kind of" works isn't that hard, but getting it really clean, smooth, and beautiful can be a nightmare. That's why I typically recommend PSPDFKit to clients. You'll generally spend much less on the license than on the custom development.
I'm attempting to create an Instagram styled app and cannot figure out a way to display media in a UITableView the way they do (either video or image in a single view). I know it most likely is a custom implementation of UIWebView or something of the sort, however I have no idea where to even begin writing a subclass like that. Things I've already tried include:
Using a UIWebView (massive memory leak, even when adding/removing the views programmatically).
Adding either UIImageView or UIWebView depending on whether or not it was a video or image (again had a memory leak)
Searching the internet for a possible way to do this
If anyone could help me out that would be awesome! FYI the media I am using is grabbed straight from my server, there is no data being gathered from a popular source such as YouTube, Flickr, etc.
i think they use UICollectionview as it allows for better customization of a table.
In terms of images and videos, use UIImageView to display all your images and MPMoviePlayerController to play videos.
I am trying to create an app for which I need a way to swipe through views. For example, while swiping through images in photo stream or camera roll. I DO NOT need to swipe through images however, I need to swipe through UIViews. I have been looking at PageViewController. However, setViewControllers:direction:animated:completion: suggests that I need a ViewController for every UIView. This doesn't seem to be what I want since I will have over 40 views that I will need to scroll through. I think I'm missing an obvious ios feature here since even iBooks has a way to go through pages of books.
I was thinking maybe having 3 ViewControllers and changing their content whenever I swipe across. But that seems very roundabout.
Please help me out!
Thanks!
Apple has provided a fairly robust example of doing this kind of thing with photos called "PhotoScroller" at http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html. It uses UIScrollViews and CATiledLayers to recreate the experience of the Photos app. You may be able to modify it to work with your UIViews instead of images.
I am using the OpenTok iOS Framework to allow video chat within my app.
However, I am trying to find a way to custom style the views that display the user and connected user's streams.
From what I have found, it seems like these views are created in OTVideoView files, but I can only access the header.
Can anyone point me in the right direction on how to customize the views for the streams so I can make it look nicer than the default styling?
Hi, Each Subscriber.view of publisher.view is really a UIView object (Technical talk: OTVideoView is subclass of UIView). You can style them however you like by applying transforms and such to the view.
For example, to adjust width/height dynamically, you can do something like this:
[_publisher.view setFrame:CGRectMake(left, top, width, height)];
Anything you can do to UIView, you can do with OTVideoView.
Here's UIView's documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Hope that helps,
Song
P.S. If you have time, check out this blog post about using Core Graphics with OpenTok's video streams to do some nifty image recognition!
http://www.tokbox.com/blog/fun-with-core-graphics-in-ios/