Using MKPolyLineOverlays and MKAnnotation efficiently - iphone

I am creating a map application, in which I am showing MKPolylineView(around 2000) and MKAnnotations with pin drop.
I want to make visible either set of MKPolylineViews or MKannotations at a time. I am managing it with 2 buttons, one button is to display set of MKPolylineViews and another for set of MKAnnotations. So I tried 2 methods to manage this scenario, which is following:
For MKAnnotations, I am removing it and adding it again.
In the case of MKPolylineViews, I tried 2 ways:
I tried to make all MKPolylineViews hidden to YES and NO to manage it visibility based on button click. In this case, when I make the MKPolylineViews visible from it's hidden state, not all the MKPolylineView are visible. I tried with alpha and hidden property. In both the cases, the result was same, not all the lines are visible. Is there any mechanism to make all the lines visible. Because the performance is good in this case.
Then I tried another way, in which I removed all the MKPolylineOverlays and add it again. This case, everything works well. But the main thread freeze the UI for some seconds. Remember I am adding around 2000 MKPolyLineView. How can I manage it.
Instead of removing the overlay, when I used the hidden and alpha property, the performance was good. But half of the lines are not visible, when I make it visible from it's hidden state. Around half of the overlays couldn't be visible.
Another help that I need is since I am using around 2000 MKOverlays, the app got free for a few seconds while zooming. I think in this case, the map is re rendering the overlay at each zoom level. Is there any way to handle it efficiently?
Can anyone help me the best way to handle this scenario.
Thanks and regards,
Sreelash

Related

How to overlap view in swift using storyboryboard

I am using xcode-14.2. I need to overlay like below image. Here is my image
I have tried in storyboard. But overlap the textfield. Here is the image like
The desired interface, of itself, is not difficult to achieve; our app uses it:
We do not, however, overlap two views; it just looks as if we do. The illusion is achieved by drawing.
So my first recommendation is that you use drawing, not true overlapping, to achieve the desired interface. If you insist upon using overlapping, then keep in mind that the order in the document outline at the left is back to front order. If you want the "select source account" to overlap in front of "available balance", you would need to bring the former to the front.

Finding a free space within current bounds of view on iOS

I have an infinite scrollview in which I add images as the user scrolls. Those images have varying heights and I've been trying to come up with the best way of finding a clear space inside the current bounds of the view that would allow me to add the image view.
Is there anything built-in that would make my search more efficient?
The problem is I want the images to be sort of glued to one another with no blank space between them. Making the search through 320x480 pixels tends to be quite a CPU hog. Does anyone know an efficient method to do it?
Thanks!
It seems that you're scrolling this thing vertically (you mentioned varying image heights).
There's nothing built in to UIScrollView that will do this for you. You'll have to track your UIImageView subviews manually. You could simply maintain the max y coordinate occupied by you images as you add them.
You might consider using UITableView instead, and implementing a very customized tableView:heightForRowAtIndexPath: in your delegate. You would probably need to do something special with the actual cells as well, but it would seem to make your job a little easier.
Also, for what it's worth, you might find a way to avoid making your solution infinite. Be careful about your memory footprint! iOS will shut your app off if things get out of hand.
UPDATE
Ok, now I understand what you're going for. I had imagined that you were presenting photographs or something rectangular like that. If I were trying to cover a scroll view with UILeafs (wah wah) I would take a statistical approach. I would 'paint' leaves randomly along horizontal/vertical strips as the user scrolls. Perhaps that's what you're doing already? Whatever you're doing I think it looks good.
Now I guess that the reason you're asking is to prevent the little random white spots that show through - is that right? If I may suggest a different solution: try to color the background of your scroll view to something earthy that looks good if it shows through here and there.
Also, it occurred to me that you could use a larger template image -- something that already has a nice distribution of leaves -- with transparency all along the outside outline of the leaves but nowhere else. Then you could tile these, but with overlap, so that the alpha just shows through to the leaves below. You could have a number of these images so that it doesn't look obvious. This would take away all of the uncertainty and make your retiling very efficient.
Also, consider learning about CoreAnimation (CALayer in particular) and CoreGraphics/Quartz 2D ). Proper use of these libraries will probably yield great improvements in rendering speed.
UPDATE 2:
If your images are all 150px wide, then split your scrollview into columns and add/remove based on those (as discussed in chat).
Good luck!

How to smoothly scroll through 600ish uilabels on a big uiscrollview (iphone)

I have a bit gantt chart that i want to be visible on an iphone.
It is 7200 x 1800px large, and consists of ~600 bars, each of which is a UILabel.
It is to look like this:
Now i've gotten it to work. And at ~100 bars, i can make it run quite smoothly by simply adding them all to the scroll view. However, with the full 600 (or more eventually) it simply crashes when i instantiate all those uilabels and add them all to the scroll view as subviews.
So what i've done is made it create only the uilabels for the currently visible rows, and as the user scrolls up and down it removes the invisible uilabels and adds the newly visible ones.
However, this jerks quite noticeably as you scroll vertically as it crosses each row boundary, and has to render another row and remove the old row.
Does anyone have any suggestions to solve this? Any ideas what is the slow part? Instantiating the uilabels, or adding them as subviews, or anything?
All help will be greatly appreciated.
Apple has some really good demo code that shows how to do this. Check out TiledScrollView.m especially the layoutSubviews method.
Other things you might consider:
If you labels are quite long horizontally you may need to break them into smaller chunks. Quite long in this context is wider than the screen.
Make sure your UILabels are opaque. Scrolling things that require compositing adds extra overhead which may account for some of your issues.
Looking at your screen shot the row and column headers are not opaque and are using alphas. Whereas this is a nice effect it may be worth temporarily making them opaque too just to see if this is contributing to your problems. I don't think this is contributing too much to your problems; the area being composited is quite small.
Just a thought, but could the issue be that even though you are caching and reusing the labels, is the scroll view still retaining them, so even though you may only have a few labels, each is being retained hundreds of times. If this is so then I would think that the scroll view is still effectively trying to manage those hundreds of rows.
So as #Nathon S asked - are you moving them? i.e. building a finite set of labels and just moving them around on the scroll view to match the viewing area. If you are hiding and re-adding to the scroll view then I would suspect a massive set of retains being the slow down. I would think that with a moving label design, you would not need to do any hides and adds after the the initial display. Which should make it very fast and lightweight.

Good strategy for creating bar chart with touch-to-view-value functionality?

I want to create a bar chart diagram. I already have a diagram component, I just need to adapt it to a bar chart. When touching one of the bars, the value shold pop up in small view.
As I can see there are several different strategies that can be applied here. What I want to know is which strategy should I use? Any of these or perhaps there are other better ideas?:
Bar is a UIButton.
Bar is a touch enabled UIImage.
Bar is a UIView.
Bar is just painted graphics and I have to transcode the touched coordinates and make some calculations in order to know what bar was touched. I don't don't believe in this strategy but perhaps there are reasons to rethink this that you can provide for me...
I assume that a UILable is the way to present the data associated with the bar?
Thanks in advance for your advice!
In my humble opinion, and having written many bar charts (and other charts)... #4 is actually the correct choice for performance and my personal preference. Creating the virtual graph in memory to map touches to bars is not difficult at all, as you are simply storing rectangles in arrays and checking to see if points are inside that rect.
CGRectContainsPoint(CGRect, CGPoint);
Now, having said that, if you want to introduce animations in to your chart, which is pretty cool stuff... then I could create a UIView composed of several UIViews (one for each bar, or bar segment), this way you can animate each bar individually without writing your own animation loop.
just my two cents.
my thoughts are that #2 and #3 are kind of the same since you'd display an image using a UIImageView. UIButton is a pretty thin layer on UIView that makes the event handling easy, but it might do things visually you don't want (or maybe you do?). Either way, it's so easy to try these variations I'd just play with it. I can't see a specific reason for #4 unless your overall strategy drives you in this direction, like maybe you start doing some drawing that is rich/complex enough that you have too many views being created.
AFA the popup display, it really depends what you mean by "pop up". Like once it pops up, do you need a way to dismiss that popup?
Have you checked out Core Plot? It is an active and powerful library that is pretty flexible and should meet all your needs.

constricting scrolling in core-plot

I would like to have my user scroll inside a CPXYGraph. I have a CPXYGraph as part of a CPHostingLayer, like in the tutorials. I enabled allowsUserInteraction, which is cool and allows scrolling. But I don't want to allow my user to scroll to 'infinity', which it seems like it allows-you can keep dragging further and further away from where the data is on a plot.
How do I constrain this so that the user can only scroll within a certain bounds?
I also enabled masksToBorder, and set the outerBorderPath and innerBorderPath to something arbitarily small, but I saw no changes, so I am not sure how those are supposed to work.
I could not set maskingPath and subLayerMaskingPath because they seem to be read only(no setters), though i feel like these two properties might be what I am looking for.
Anyone has run into this situation? Would be glad if someone could shed some light. Thanks!
The masking properties only affect the drawing. You need to use the globalXRange and globalYRange properties of your plot space. These define the maximum range that can be scrolled into view. See the example in CPTestApp.