Reproducing Popular iOS Controls - Part 17: | Ray Wenderlich Videos

This video will teach you how to create an interactive graph that lets the user move through its data with their finger.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5298-reproducing-popular-ios-controls/lessons/17

Hi! Great course, love it!

I wonder for this video: shouldn’t the y coordinate be :
y = graphMiddle + (data point price - opening price) ?

So that if the data point price is over the opening price, the point should be above the graph middle ?

Thanks !
Fred

@leamars Can you please help with this when you get a chance? Thank you - much appreciated! :]

Also, shouldn’t the x calculation be the following ?
var x = min(max(touchLocation.x, minX), maxX)

instead of
var x = min(max(touchLocation.x, maxX), minX)
as shown in the video ?
Because that causes a weird behaviour when you pan to the maximum (it comes back to the origin …)

Thanks
Fred

Oh wow! Yes! You are completely correct. What a silly mistake :woman_facepalming:t2:

You’re right again @freddyf! Thanks for paying such close attention to the course and the code. It will be a really helpful addition to all the other viewers! :slight_smile:

Honestly, I’m going to blame this oversight a little on the fact that the data is fictional so it didn’t LOOK wrong to me. But that’s a great case FOR using real data even in tutorial and example applications!

Cool! Glad I could be helpful :wink:

1 Like

Hello! Great course so far!!

Quick question regarding drawRect:. I realize this might be a bit more beyond the scope of this course, but curious about performance when it comes to drawing the graph in drawRect: vs creating a new CAShapeLayer and adding it as a sublayer. My understanding is that’s a bit more performant because you can better control when the layer is being redrawn, but not able to find a ton of information around this and was wondering if you had any recommendations for this.

Thanks!

@leamars Can you please help with this when you get a chance? Thank you - much appreciated! :]

You mean not using drawRect at all, but instead having a CAShapeLayer that you would change continuously?

Oh sorry, just saw your response @leamars. I actually just went through the Drawing in iOS course to gain a better understanding. I still have some questions as to when to use core graphics/drawRect: vs when to have a hierarchy of CAShapeLayers (which from what I understand, is faster). Let me ask this question over in that course, though, since I think it might fit better here. I’ll add a link in a bit.

Thanks!

1 Like

That sounds like a great idea :D! Do report what you find out!