Note that there are some explanatory texts on larger screens.

plurals
  1. POSerious issues with getting touch coordinates
    primarykey
    data
    text
    <p>I have a simple application that shows the user an image (in a UIImageView) whereby they touch on a part of the screen and then on the next screen the same image is shown (in a UIImageView) but now has a "signature" overlayed on it. The issue I am having is that it seems that the x,y coordinates returned from the touches do not seem to map properly on the UIImageView on the second screen. </p> <p>For instance when I touch the bottom of the screen I get: X: 157.000000 Y: 358.000000</p> <p>but the bottom of the screen should be 480 ? since my screen dimensions are: SCREEN HEIGHT AND WIDTH AT X: 320.000000 Y: 480.000000. This causes the signature to be placed at a DIFFERENT spot than what the user intended.</p> <p>I use the following code to get my touch coordinates:</p> <pre><code>-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"TOUCH HAPPENED"); UITouch *touch = [touches anyObject]; CGPoint touchCoordinates = [touch locationInView:self.view]; NSLog(@"X: %f Y: %f",touchCoordinates.x, touchCoordinates.y); } </code></pre> <p>I am using the following code to place the "signature" with the values I get from the touch:</p> <pre><code>CGRect screenRect = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContext(screenRect.size); [pageImage drawInRect:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)]; // this is the original image NSLog(@"SCREEN HEIGHT AND WIDTH AT X: %f Y: %f",screenRect.size.width, screenRect.size.height); NSLog(@"PLACING IT AT TOUCH COORDINATES X: %f Y: %f",sigLocation.x, sigLocation.y); UIImage *shieldLogo = [UIImage imageNamed:@"shield_bw.gif"]; [shieldLogo drawInRect:CGRectMake(sigLocation.x, sigLocation.y, shieldLogo.size.width/2, shieldLogo.size.height/2)]; [theSignature drawAtPoint:CGPointMake(sigLocation.x+24.000000, sigLocation.y) withFont:[UIFont fontWithName:@"Arial" size:8.0]]; [theSignature2 drawAtPoint:CGPointMake(sigLocation.x+24.000000, sigLocation.y+ 8.000000) withFont:[UIFont fontWithName:@"Arial" size:8.0]]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [image setImage:resultingImage]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload