1

So I am using GLKViewController and GLKView. I am debugging my app on iPhone 5s and if I view the drawableHeight and drawableWidth for the view it shows as 1136 and 640 which is correct for iphone 5s. However when I check the following code.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    startTime = CFAbsoluteTimeGetCurrent();
    self.lastGestureTime = startTime;
    active = true;
    UITouch *touch = [ touches anyObject ];
    CGPoint _location = [ touch locationInView:self.view ];

and I click the bottom-right of the screen I get the location as 316 and 533 which is approximately half of what I expect the co-ordinates to be. So the location anywhere on the screen is getting sized to exactly half of what I expect it to be. My UI displays correctly so the buttons are all in the right place, but the location from locationInView comes out wrong ( I think it is exactly half of what it should be ). Any help would be great.

nishant
  • 736
  • 1
  • 12
  • 22
  • 1
    Did you heard about `scale` ... and why the `scale` it's 2 for iPhone 5s? https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreen_Class/index.html#//apple_ref/occ/instp/UIScreen/scale – TonyMkenu Nov 19 '14 at 22:29
  • So... {316,533} * `scale` -> {632,1066} – TonyMkenu Nov 19 '14 at 22:32
  • I did some digging around and found that [ view.layer.contentsScale ] = 2.0. So I adjusted the code as follows and it seems to work. Not entirely sure if I need to be setting contentsScale to 1 for GLKView or whether let it remain 2 and then adjust my code like below: float contentScaleFactor = [ self.view.layer contentsScale ]; Vector2 location; location.v[0] = _location.x * contentScaleFactor; location.v[1] = _location.y * contentScaleFactor; – nishant Nov 19 '14 at 22:33
  • http://stackoverflow.com/a/25872821/1702413 – TonyMkenu Nov 19 '14 at 22:38

0 Answers0