public
Created

Simulating a 7.85 inch iPad

  • Download Gist
sevenInchAppDelegate.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//Put this into your AppDelegate.m
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Your app launch code here...
[self.window makeKeyAndVisible];
[self simulateSevenInchIpad];
return YES;
}
 
- (void)simulateSevenInchIpad
{
//simulate 7.85 inch iPad
//scale window
CGFloat scaleFactor = 7.85/9.7; //try 768.0/1024.0 for the size of two apps on a 10" iPad side by side!;
self.window.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
//we also want to scale the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self
selector:(transformKeyboardForSevenInchIpadSimulation)
name:UIKeyboardWillChangeFrameNotification];
}
 
- (void)transformKeyboardForSevenInchIpadSimulation
{
//finding the window that hosts the keyboard - from http://stackoverflow.com/a/6457567/534888
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
if (![window.class isEqual:UIWindow.class]) {
//keyboard window found... probably
 
CGAffineTransform identityTransformUpsideDown = CGAffineTransformMakeRotation(M_PI);
CGAffineTransform identityTransformRotatedLeft = CGAffineTransformMake(0, 1, -1, 0, -128, 128);
CGAffineTransform identityTransformRotatedRight = CGAffineTransformMake(0, -1, 1, 0, -128, 128);
//if the window is unscaled, scale it
if (CGAffineTransformIsIdentity(window.transform)
|| CGAffineTransformEqualToTransform(identityTransformUpsideDown, window.transform)
|| CGAffineTransformEqualToTransform(identityTransformRotatedLeft, window.transform)
|| CGAffineTransformEqualToTransform(identityTransformRotatedRight, window.transform))
{
CGFloat scaleFactor = 7.85/9.7; //768.0/1024.0;
window.transform = CGAffineTransformScale(window.transform, scaleFactor, scaleFactor);
}
return;
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.