Sometimes, if you don’t want to deal with autolayout or it simply isn’t performing in the way you want, the solution to your problem may be to use a separate storyboard for each device. To do that, add this code to your AppDelegate.m and make sure you have the separate storyboard files that you need.

Call this method in your application:didFinishLaunchingWithOptions: with this command:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self initializeStoryBoardBasedOnScreenSize];

AppDelegate.m

-(void)initializeStoryBoardBasedOnScreenSize {
    UIStoryboard *storyboard = nil;
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    {    // The iOS device = iPhone or iPod Touch
        CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
        if (iOSDeviceScreenSize.height == 480)
        {   // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
            NSLog(@"Loading iphone 4 storyboard");
            // Instantiate a new storyboard object using the storyboard file named MainStoryboard_iPhone
            storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        }
        if (iOSDeviceScreenSize.height == 568)
        {   // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
            NSLog(@"Loading iphone 5 storyboard");
            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
           storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
        }
        
    } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
        // The iOS device = iPad
        NSLog(@"Loading ipad storyboard");
        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
        storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
    }
    // Instantiate the initial view controller object from the storyboard
    UIViewController *initialViewController = [storyboard instantiateInitialViewController];
    
    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    // Set the initial view controller to be the root view controller of the window object
    self.window.rootViewController  = initialViewController;
    
    // Set the window object to be the key window and show it
    [self.window makeKeyAndVisible];
}

Parallax effect
Parallax effect

In iOS 7, Apple introduced a Parallax effect to the app screen. There is an API available for you to add this effect to your apps. This code lets you add a parallax effect to your apps in iOS 7. I haven’t tested this myself, but it looks like it should work.

Let me know how it goes!

UIInterpolatingMotionEffect *interpolationHorizontal = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
interpolationHorizontal.minimumRelativeValue = @-10.0;
interpolationHorizontal.maximumRelativeValue = @10.0;

UIInterpolatingMotionEffect *interpolationVertical = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
interpolationVertical.minimumRelativeValue = @-10.0;
interpolationVertical.maximumRelativeValue = @10.0;

[self.background addMotionEffect:interpolationHorizontal];
[self.background addMotionEffect:interpolationVertical];

This is a UIAlertView that has a button linking to this website. It implements the UIAlertView delegate on self.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"About"
                                                    message:@"Application developed by Kevin Yavno\n\nVersion 1.0"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:@"Website",nil];
    [alert show];
}

This is the implementation of the UIAlertViewDelegate. It’s not the best practice to compare the button title to a hardcoded string, but it gets the job done in this simple app.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Website"])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://kevinyavno.com"]];
    }
}

Here is an example of how to present iOS’s built in Tweet Compose View. This code simple allocs the view controller, then sets the initial text. After setting the completion handler using a closure (lambda function if you want to get technical) it then finally presents it overtop of our current view.

You need to link the Twitter.framework library with your source to use this code.

Continue reading