I want to have a full screen UICollectionView with paging, with a UIWebView in every cell.
The WebView should scroll up and down, and the CollectionView should move pages left and right.
Also, I want the pages on the cells will preload so when the user move to a certain page the html page will already be there.
What is the correct way to handle this?
It's hard to put it all in here, so check out if this project gets you closer to solving your problem.
Notice that there is no preloading, because if you'll write your own html and there won't be any network calls, you don't need to preload pages - changes will be instantly visible to your users.
You always gonna have to reload the UIWebView in UICollectionViewCells because they are reusable, but if you want you can make a hack, an UICollectionView that it is 3 times bigger than the frame of your main view it has to begin in the second page and finish in the one before the last.
It is going to have always 3 webviews preloaded (but you can make the hack bigger if you want) or you can make a UIScrollView with pagination activated which always gonna have all of the webview preloaded.
Related
I am currently building an objective c application in xcode that features a full screen horizontally scrolling collection view with cells that take up about 80% of the screen; similar to that of Instagram, Vine, etc. Initially in these cells are video thumbnails that are loaded from a backend source upon the loading of the view.
Since it would be terribly inefficient to load all of these videos at once, I am trying to find a way to only load one video at a time while the user scrolls through the collection view.
The way I am achieving this right now is by using the scrollViewDidEndDecelerating method to calculate whichever cell is in the center of the screen after scrolling, and then beginning to load the video, as well as the scrollViewDidScroll method to stop loading the video. This implementation is shown below:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//calculate which cell is in the center
//load video in respective cell
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//stop loading video
}
As you all can probably see, this generates a lot of ux problems:
The video doesn't start loading until scrolling has stopped
completely
This approach doesn't account for drag gestures to
navigate the Collection View
Once a video has loaded, any drag or
scroll stops loading/playing the video
There are times where no video is loading, between scrolls
I am trying to turn this current approach into a system similar to the Instagram method of loading videos, which is as follows:
A video begins to load as soon as it begins to show up on the screen while the user scrolls
A video stops loading when a different video begins to appear on the screen while the user scrolls.
One video is always being loaded, there is no downtime between loading one video and another
I understand that in order to achieve this functionality, these loading functions will need to be done on a background thread in order to allow for seamless scrolling which I can handle, I just need to know which methods I should be using instead of the ones i'm using now in order to achieve this functionality.
You should make it such that the video uses "lazy loading" to load its contents/thumbnail.
To make it play when cell is at center, use scrollViewDidScroll to detect if the cell is completely showing by method indicated at this answer
I'm currently trying to render html content into custom NSTableCellViews inside an NSTableView. This is to render emails inside an email thread individually. On selection, the NSTableCellView either expands to show the rendered email, or contracts to hide it. It seems to be working fine with a combination of:
tableView:viewForTableColumn:row:
tableView:heightOfRow:
tableViewSelectionDidChange:
and:
noteHeightOfRowsWithIndexesChanged:
reloadDataForRowIndexes:columnIndexes:
Each NSTableCellView has a WebView as its child. The rendered content shows up fine until I start scrolling heavily at which point, off-screen WebViews lose their rendered content. If I force a re-render by contracting and expanding the NSTableCellView, the content appears fine.
Is there a delegate method/a way to fix this? Or should I use something other than WebViews to render html inside an NSTableCellView?
In case someone stumbles here into the future, the solution I used was to set the NSTableView.usesStaticContents to YES. This prevents makeViewWithIdentifier from recycling cells and hence allows the WebView's to persist in different NSTableCellViews.
This will obviously use more memory, but since there is a definite limit to the maximum number of cells inside an email thread, the increase is within acceptable bounds.
I've been struggling with first responder problem. I put web controller (UIWebView) inside UITableViewCell and now I would like to scroll vertically my table and not affect UIWebView (this case may be done by disabling scrolling scrollview from UIWebView). However problem appears when user zooms into web content, then I want scroll horizontally through web content and still vertically scroll in table (cause cell will be resized to zoomed content).
There is a property called 'multipleTouchEnabled' that should disable the pinch gesture, but I think the user would still be able to double-tap (assuming the cell doesn't consume this gesture). Why not, instead of creating multiple UIWebView's (which have a large overhead) don't you create one hidden UIWebView that loads a website and caches an image, then load this image into the cell.
Ultimately, if you still wanted to use the UIWebView approach, you could probably subclass it and override hitTest/touches methods or handle the gesture recognizers yourself.
Also, if this is for iOS8 I would be using the WKWebView instead.
I need to show a paginated slideshow of moderately DOM-intensive HTML pages in an iPad application.
All documents are tailored for iPad screen so there is never any scrolling inside UIWebViews.
I decided to put UIWebViews inside UIScrollView for pagination.
It works really well and smooth after all web views have rendered their content.
However, I can't afford waiting for 20, 30 or 50 web views to load before user can scroll: it takes minutes.
I tried to anticipate swipes in scrollViewDidScroll handler and pre-load a few next pages as user keep scrolling.
This worked much better (no performance difference between 10 or 150 web views).
However calling loadHTMLString in scrollViewDidScroll handler causes scrolling to lose it smoothness.
I don't care if it takes a second longer to show a particular UIWebView—all I want is for scrolling to be smooth and available as soon as possible, and to lazily preload UIWebViews on the go.
How do I achieve that?
This is a difficult problem and there is no easy/elegant way to solve it.
One way to speed up the scroll would be to lazy load the pages as you stated in your question. However, in order to ensure smoothness you would have to control when the loading happens.
So say you began by loading the first 5 pages on initial launch. When the user scrolls to page 2 and STOPS, you begin loading page 6. As soon as the user starts scrolling again you pause the loading only to resume when they have stopped on a new page. Pausing the loading in between will help smooth out the scrolling. Also, make sure you release data when possible because it can build up and hinder smooth scrolling down the line.
Another option would be to have the UIWebViews begin loading only as soon as the user stops on the page. So say I scroll to page to, once the scrolling stops I begin to load the HTML. This is not as "pretty" as the first options but it will ensure that the scrolling is smooth.
Another option, this one is a bit out there, is to run through and load all the HTML pages rich text. Leaving out all the DOM intensive stuff. Then grab a screen shot of those semi-loaded page using this method. When the user stops on the page you load it all the way including the DOM intensive stuff. This will let the user feel as thought they are scrolling quick with everything loaded.
Here is a great scrolling class that I have used before.
Here is some code to help with method 3.
Good luck and I hope that this helps!
EDIT:
Here is a great post from the guys at LinkedIn on how they solved webView scrolling problems. It would be worth a read.
In my app I have a webview that is used solely for displaying the facebook page.
However, the client does not want the top blue bar of facebook to appear; he wants to hide it.
Is there a way to do this?
The bar is 45 pixels, so what I did is I moved the UIWebView in IB in such a way that its top 45 pixels are behind my navigation bar (thus not appearing).
However, this is not an ideal solution, as the user can see that content when he scrolls up, before bouncing. He can see but not touch it, which will be frustrating for some users.
I tried turning the bouncing off, but then the UI becomes too rigid, and not fluid.
I looked up in Google and Stackoverflow for a couple of hours but didn`t find a solution.
Thanks a lot!
You'll have to edit the HTML/CSS of the page itself to hide the HTML elements in question, probably using regular expressions, and feed it into your UIWebView with loadHTMLString:baseURL:.
I've done similar manipulating before and it works, but... it's a different ballgame when the webpages in question don't belong to you. Any time Facebook updates their layout, your app behavior might change until you have time to get an app update approved. Clients want what they want, but make sure your client knows what he's asking for!
First test out the javascript code used to hide whatever elements in the webpage and then pass up to stringByEvaluatingJavaScriptFromString of UIWebView to run it.