I'm using a UICollectionView on my iPad 3 to display a dashboard of BarChart using CorePlot. I have around 3 pages of 6 BarChart.
When user scrolls the UICollectionView there're some lags.
I have changed the theme of my BarChart from kCPTDarkGradientTheme to kCPTPlainBlackTheme and the scroll is much better but it still lags a little.
From instrument it seems it takes some times (160ms) in -(void)recursivelyRenderInContext:(CGContextRef)context from CPTLayer.
Any idea how to improve it?
Regards,
Sébastien.
Solid colors render a lot faster than gradients, so that explains the improvement when you changed themes. Are you caching the generated graph images so they only have to render once? The iOS version of the Plot Gallery example app use a table view to show the graph thumbnails, but it might give you some ideas how to structure your app for better performance.
Related
could you please give me some advices please. I've been struggled for days.
My goal is implement continuous scrolling to show pages from document. Each page is controlled by a viewController. And user should be able zoom in and out.
Should i do it from scratch with scrollView or collectionView? which is better and more memory efficient?
Or there are any off-the-shelf solution for this? (i've searched in Github without success, UIPageViewController is definitive not a solution because it doesn't allow continuous scrolling and only show a whole page)
Thank you very much
Image:
example continuous scrolling
A collection view works just fine for continuous scrolling, and makes efficient use of memory. (Cells are recycled.) If the total contents of your scrolling area are too much to fit into memory you will want to load each page's contents into memory as it scrolls into view, and release it when it scrolls off. (Perhaps have your model store file URLs to each page's contents, and save the page contents into the cell.)
As for zooming, the best way to do that depends on what you mean. If the contents are vector contents like a PDF, you could simply re-render the vector image as the user scrolls. If the contents are very high resolution images you might need to create a mipmapped tiled rendering framework, or use somebody else's. I've written my own mipmapped tiled rendering framework before. It's doable, but a lot of work.
(You take the original huge image and break it into smaller square tiles. You then render the original image into tiles at 50% scale and save those, and then 25%, and then 12.5%, etc, until you get to a size where a single image fills the screen.)
I'm loading a very large image (8000x8000) into an UIImageView that's in a UIScrollView. This works but it consumes a lot of memory and takes a couple of seconds to load.
I've looked into a better approach and all the examples I have found are based on a 2010 WWDC example called PhotoScroller. This example uses a custom UIView with CATiledLayer to break the large image into smaller tiles and draw them to the screen.
https://github.com/master-nevi/WWDC-2010/tree/master/PhotoScroller
Is there a more modern way to do this in iOS 13 or is this still the best approach?
It is still the best approach. 8000x8000 is huge. You cannot load the whole image at once. CATiledLayer means you only need a few tiles loaded at a time — just the portion of the image that the user is looking at at the moment.
I’m working on various iOS apps and I need an interface with the following capabilities:
I have a scrollview (covering most of the screen) which is scrollable both directions
This scrollable view contains a lot of rectangles. These rectangles are intractable. User can modify them, move them around, create and delete. So ideally they would be all CALayers or UIViews.
The problem is because there could be 100s or 1000s of those displayed at once, CALayers or UIViews may not be very efficient.
The scrollview could be 10-20 times bigger than the screen size itself. And fully covered with these shapes. So when the user scrolls it shouldn’t see any flickers or shapes appearing after the scrolling is done. e.g. If I use CATiledLayer and user scrolls, you can see things drawn after scrolling is done.
Smooth zooming. Zooming out is particularly challenging, because the shapes would need to be drawn on parts of the view which are going to become visible. Also, ideally I’d rather not use something like CGAffineTransform to perform scaling, I like to have a pixel accurate scaling.
I’ve tried various things, but I can’t seem to be able to get decent frame rates even on iPhone 6. Even tried drawing every frame, but it’s too expensive Core Graphics to handle it. Is there code examples someone trying to do a similar thing or an open source library? I’m trying not to use OpenGL, I feel like it’s an overkill, but I will try it if I have to. FYI, I have no experience in OpenGL yet.
Procreate for iPad does what I’m trying to do perfectly, it’s super responsive and zooming is pixel accurate. I know they use OpenGL and I’m not making drawing apps. The reason I mention it is because it shows what I’m trying to do is possible.
I think you need to move from UIKit to some 2d or 3d engines:
Cocos2D
Sparrow
Unity
OOlong
In my app, i got core plot bar chart on a scroll view with paging, on IPhone all work fine , you page between different pages, one of them is the plot with its own touch gestures and properties.
Problem starts when i run the same code on IPad. plot becomes slow and laggy, all touch gestures takes a lot of time to response and the whole scroller paging becomes heavy and slow.
the chart itself contains 100 points or so (not so big).
I've read somewhere that the change of plot space between IPhone and IPad makes these changes in performance because the IPad renders 4 times the graphics. Did anybody had this problem before? Is there something i can do to make performance better on IPad without limit or lose preform data?
Unfortunately Core plot is a very slow library which can only handle a few hundred data-points (or less in some cases).
I wrote an answer here which describes a performance comparison between iOS chart components. One of the charts tested was core-plot and it couldn't do the first test!
Without knowing the specifics of your app, here are some general performance hints:
Set all line styles and fills that you don't need to nil rather than transparent colors.
Use solid color fills rather than gradients or images where possible.
Reduce the number of axis labels, tick marks, and grid lines if possible. Perhaps eliminate minor tick marks and grid lines completely (set the corresponding line styles to nil).
Only call -reloadData when a significant portion of the plot data changes. Use the insert and delete methods when possible. See the "Real Time Plot" in the Plot Gallery example app.
In my App I need to draw graph data with different datamodels that frequently change and can not be generalized. This graph data must be editable with a slider or a segmented control.
The idea is to load all necessary data to draw the graph from the server. Is html5 the right solution? Can the iPad-UI-Controlls used to manipulate the graph?
Where do I start and how much work is it?
Currently I'm using Core Plot to draw the graph - but I need to model my graph data on the server.
Option 1: If you are developing for Android as well or you are better at javascript, then you can use HTML5.0. Have a look at http://www.sencha.com/products/touch/charts/
Option 2: If you want to develop it natively for iPad(which I feel is a better option), then please look at google library for graph http://code.google.com/p/core-plot/ and Is there a good charting library for iPhone?
I extended the work of this gentleman:
http://buildmobile.com/creating-a-graph-with-quartz-2d/#fbid=EKAB22zV7It
And I'm quite pleased with the results. It took me about a week to get my graph able to draw a stock chart with scrolling, pinching zooming, 3 different symbol indicators, a secondary plot line, tap-able data points with a little custom popover showing details, and a few annotations. Not bad considering the overall complexity, and largely thanks to the detailed walkthrough.
He also talks about why he didn't use Core Plot.
Good luck,
Damien