Points Versus Pixels ios

AMH picture AMH · Jun 29, 2011 · Viewed 7.1k times · Source

I have uiview , that I zoom in and out in it

I associate it with pinchRecognizerMeasure using

pinchRecognizerMeasure = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(MeasureAndDraw:)];
[pinchRecognizerMeasure setDelegate:self];
[DrawLine addGestureRecognizer:pinchRecognizerMeasure];
[pinchRecognizerMeasure release];

the code of MeasureAndDraw

    // get position of touches, for example:
    NSUInteger num_touches = [pinchRecognizerMeasure numberOfTouches];

    // save locations to some instance variables, like `CGPoint location1, location2;`
    if (num_touches >= 1) {

        DrawLine.startPoint = [pinchRecognizerMeasure locationOfTouch:0 inView:DrawLine];
    }
    if (num_touches >= 2) {

        DrawLine.endPoint = [pinchRecognizerMeasure locationOfTouch:1 inView:DrawLine];
    }

startPoint , endPoint are CGPoint , I want to get the equivalent pixel to it

what shall I do is it correct to do something like

startPoint.X * DrawLine.contentScaleFactor to get the pixl x coordinate or what shall I do

I read http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html , but get confused

any suggestion

Answer

Abizern picture Abizern · Jun 29, 2011

Have a look at the contentScaleFactor property of UIView to translate between points and pixels on the device if you really need to.