Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.31 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Move a CGPoint dependant on device orientation
  2. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
  3.        
  4. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  5. {
  6.     if ( (self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) ) {
  7.         myPoint = CGPointMake(320/460*myPoint.x, 460/320*myPoint.y);
  8.     }
  9.     else {
  10.         myPoint = CGPointMake(460/320*myPoint.x, 320/460*myPoint.y);
  11.     }
  12. }
  13.        
  14. - (CGPoint)adjustTouch:(CGPoint)aTouch forOrientation:(UIInterfaceOrientation)aOrientation; {
  15.  
  16.   CGPoint touchLocation = CGPointZero;
  17.  
  18.   switch (aOrientation) {
  19.     case UIInterfaceOrientationPortrait:
  20.       touchLocation = aTouch;
  21.       break;
  22.     case UIInterfaceOrientationPortraitUpsideDown:
  23.       touchLocation.x = aTouch.x;
  24.       touchLocation.y = 480 - aTouch.y;
  25.       break;
  26.     case UIInterfaceOrientationLandscapeLeft:
  27.       touchLocation.x = aTouch.y;
  28.       touchLocation.y = aTouch.x;
  29.       break;
  30.     case UIInterfaceOrientationLandscapeRight:
  31.       touchLocation.x = 480 - aTouch.y;
  32.       touchLocation.y = 320 - aTouch.x;
  33.       break;
  34.     default:
  35.       break;
  36.   }
  37.   return touchLocation;
  38. }