Assignment 3

43 views
Skip to first unread message

James

unread,
Dec 31, 2011, 11:46:50 AM12/31/11
to iPhone Application Development Auditors
So I finished up assignment 3 with the exception of implementing
contentScaleFactor. I'm struggling to figure out how to implement its
use in my GraphView's drawRect:. Does anyone have any pointers on how
this works when drawing Points (or dots) across the X axis?

Thanks,
James

Dave Kliman

unread,
Dec 31, 2011, 12:38:04 PM12/31/11
to iphone-appd...@googlegroups.com
you're way ahead of me.. i'm still in the middle of 2, considering 1 isn't even due until after jan 9!

--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To post to this group, send email to iphone-appd...@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-aud...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.



jonathan.nyc

unread,
Dec 31, 2011, 5:07:15 PM12/31/11
to iPhone Application Development Auditors
James, when you're writing for retina display the dimensions of the
views are the same as before. The maximum height is still 480. Max
width is still 320.

The difference is in precision. If you were using a number of points
to define a section of a graph, in retina display you should use twice
as many.

For example, you're starting out with (0, 25) and (1, 35)

In retina display, you will still use those points, but retina can
also use an in-between value such as (0.5, 32) so the device can
display a more refined curve. Shouldn't take a lot of code
adjustments to do this.

Jonathan

James Massara

unread,
Dec 31, 2011, 6:25:00 PM12/31/11
to iphone-appd...@googlegroups.com
Hi Jonathan,

I'm still a bit confused. :) I'm iterating over the width of my viewing space (rect.size.width). I calculate x, doing the conversion based on origin and scale, and then use that to determine y. I then convert those values back to rect's coordinate space. Assuming I understand correctly, I would then do this?

if (!i) CGContextMoveToPoint(context, x, y);
else {
if (self.contentScaleFactor > 1) CGContextAddLineToPoint(context, x-0.5f, y);
CGContextAddLineToPoint(context, x, y);
}

Thanks for your help!
James

jonathan.nyc

unread,
Dec 31, 2011, 7:08:22 PM12/31/11
to iPhone Application Development Auditors
James, there are some problems with your code.

You've got two "add line" commands. Your code will be simpler if you
use a single command for every line you add.
The condition tests for the scale factor being greater than 1 &
assumes its value is 2 in that case. You'll have to fix your code if
Apple releases a
screen with an even better resolution someday.
You've coded a single value of y for two different x values. That's
incorrect, of course.

I was able to accommodate retina display with minor revisions to two
lines of code. So look for something very simple to accomplish
this.

Duane Bender

unread,
Dec 31, 2011, 8:16:43 PM12/31/11
to iphone-appd...@googlegroups.com
I haven't gotten that far yet on Assignment 3, but I have given it some thought, and I really don't think I understand what difference it makes. I mean, you could use ContentScaleFactor to calculate Y values for more X values, but as far as I can find, Core Graphics only draws to points, not to pixels.

Duane

jonathan.nyc

unread,
Dec 31, 2011, 9:36:08 PM12/31/11
to iPhone Application Development Auditors
The CGFloat values can have a high level of precision of course. On
an old device, an algorithm calculates how to display an image, which
can be highly-detailed, using a 320x480 grid.

With retina display it's the same process, except the grid is 640x960,
allowing for less reduction in resolution.

Writing to a point at a fractional value on an old device is wasteful,
since it will be interpolated out of existence.

But with retina display the same step can result in a superior
display, which is why it's part of the assignment.

zak

unread,
Jan 1, 2012, 2:07:52 AM1/1/12
to iPhone Application Development Auditors
FYI:I am working the assignment 3. And I am using following logic to
determine how to iterate though. Also I wrote to helper ViewToGraph,
GraphToView.
CGFloat pixel = 1 / self.programView.contentScaleFactor;
for(CGFloat xGraph = self.programView.bounds.origin.x; xGraph <
self.programView.bounds.size.width; xGraph+=pixel)
{

Duane Bender

unread,
Jan 1, 2012, 9:27:01 AM1/1/12
to iphone-appd...@googlegroups.com
Ah, so we can draw to pixels by addressing them as half-points! Even though the parameters to the drawing functions are floats, I was thinking in terms of the points being represented by integer pairs. As I said, I'm not there yet, but I now can see how this will work. Right now I have to figure out what's wrong in my protocol/delegate setup.

Duane

James

unread,
Jan 1, 2012, 9:46:34 AM1/1/12
to iPhone Application Development Auditors
Thank you Jonathan and zak for the guidance. On to assignment 4. :)

James
Reply all
Reply to author
Forward
0 new messages