UIView has some convenience methods you can use to convert a CGRect to and
from different views’ coordinate systems. Look at the documentation for
-convertRect:fromView:<http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-BBCDBGGG>for
an example. Now,
UIScreen isn’t a view, but you can probably combine its
-applicationFrameinstance method with the
UIWindow (which *is* a view) to get something approximating the screen’s
frame relative to your view’s coordinate system (which is what I think
you’re asking for).

Jeff Kelley


On Fri, Jul 1, 2011 at 2:43 PM, Development <developm...@fornextsoft.com>wrote:

> I am sure I am missing something simple but I've tried everything I can
> find
>
>
> I need to convert a rectangle in a NSView to a corresponding rectangle in
> screen coordinates.
>
> originally I was using this code:
>
>                selected.origin.x = selection.origin.x / ([imageView
> frame].size.width/screen.size.width);
>                selected.origin.y = selection.origin.y / ([imageView
> frame].size.height/screen.size.height)+25;
>                selected.size.height = selection.size.height / ([imageView
> frame].size.height/screen.size.height);
>                selected.size.width = selection.size.width / ([imageView
> frame].size.width/screen.size.width);
>
>
> and it worked. However I have had to change the means by which I was
> capturing the screen to CGDisplayCreateImageForRect
>
> I want to select an area in a view that represents the entire screen. I
> need that rectangle then to be translated to the correct size and origin in
> screen coordinates.
>
> The above code creates a rectangle of the correct size but the origin is so
> far off I cannot image how to fix it.
>
> I have tried having the view itself use convertRectToBase passing the
> screen bounds. This creates a rectangle of the correct size but the origin
> is always, no matter what, 15,183.
> I'm totally lost here and don't even know what to search for now that my
> other attempts have failed.
> Could some one help me out?
> I'm hoping to find something with low overhead as clicks are a factor.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to