Sunday, March 4, 2012

Custom Transition Animation for Modal View Controllers

Needed to implement a custom animation (push from right/left when presenting a modal view controller, and then pushing out to the other direction when dismissing the dialog).
Yosi found this snippet: http://blog.radi.ws/post/5924267283/custom-modal-uiviewcontroller-transitions
by Evadne Wu. This was so cool, and I think I made it a bit more fun by creating a UIViewController category to do that (I was a bit lazy, so I only implemented the Push in/out transition, but this can be easily extended):


//
//  UIViewController+Transitions.h
//  Labgoo Misc
//
//  Created by Israel Roth on 3/4/12.
//  Copyright (c) 2012 Labgoo LTD. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIViewController(Transitions)

- (void) presentModalViewController:(UIViewController *)modalViewController withPushDirection: (NSString *) direction;
- (void) dismissModalViewControllerWithPushDirection:(NSString *) direction;

@end


and the implementation:

//
//  UiViewController+Transitions.m
//  Labgoo Misc
//
//  Created by Israel Roth on 3/4/12.
//  Copyright (c) 2012 Labgoo LTD. All rights reserved.
//

#import "UIViewController+Transitions.h"

@implementation UIViewController(Transitions)

- (void) presentModalViewController:(UIViewController *)modalViewController withPushDirection: (NSString *) direction {

    [CATransaction begin];
    
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;
    
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];
    
    [self presentModalViewController:modalViewController animated:NO];
    
    [CATransaction commit];

}

- (void) dismissModalViewControllerWithPushDirection:(NSString *) direction {

    [CATransaction begin];
    
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;

    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];
    
    [self dismissModalViewControllerAnimated:NO];
    
    [CATransaction commit];
    
}

@end



to use it, you import "UIViewController+Transitions.h" in your file and call the presentModalViewController:withPushDirection:
the direction parameter receives core animation transition sub-types such as kCATransitionFromRight

Enjoy...




And a message from our advertisers:


Toptal provides remote engineers and designers of high quality. I recommend them. Follow this link (full disclosure: this is my affiliate link):
https://www.toptal.com/#engage-honest-computer-engineers-today



Wednesday, November 30, 2011

Growing your revenues in new markets


As we indie developers struggle to get our apps noticed, downloaded, used and pay our bills, we should maximize whatever means we have to get the app available to as many users.
One often neglected direction is localizing your app to serve users in non-English speaking countries.
Publishing your app in a local language can open for you new markets and maximize your revenues, and the effort needed is really not that great.

There are three parts for making your app available in multiple languages:

Design Time

While at the design and conception stage of your app, give some thoughts to issues such as:

  • Using text vs. using images for buttons, menus or other app elements. Using images gives you more flexibility as to the appearance, fonts, effects of your app text. Using strings makes it easier to change your texts or localize them.
  • Using special fonts which may or may not have the characters you need in foreign languages. If you did decide to use strings, and opt for using custom fonts, make sure the font has the characters for all the languages you want to support. In many cases it is simpler to use unicode fonts from the set of built-in fonts, but sometimes you do need a custom font to get that special look. Keep the character set issue in your thoughts.
  • Designing for variable size strings for labels or other GUI elements. Text may change size when you switch to a different langauage - width, height and in some cases number of lines will have to be flexible. At the design stage just keep this in mind, and allow your self room for flexibility
Development

During development, you should follow Apple guidelines for localization. Refrain from using hard coded text strings, and go for the NSLocalizedString, localized resources, etc.
Also bear in mind the issue of text size and location. You can use NSString method sizeWithFont to get the dimension of text:


font = [UIFont fontWithName:name size:size];
if( font )
   CGSize dim = [string sizeWithFont:font];


Sean Berry published an excellent tutorial with examples on Ray Wanderlich's blog site: http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial

Translation

In many cases I found Google Translate sufficient (especially for languages I have some experience with), but a more professional approach which is not so expensive is available. I am recommending a service called One Hour Translation This service is very reasonably priced (around 5-10 cents per word) and the turn around time is phenomenal - I got all my translations within 30 minutes (!!!)
I have no way to judge the translation quality, but they do give you an option (for slightly more money) to use an expert translator for your particular domain, and an option to get the translation proof read by another person.

One Hour Translation

Wednesday, November 2, 2011

My Art and other interests

I decided to separate my art related posts and place them in a separate blog. You can check them here: http://sroolart.blogspot.com/
I also created a new blog for posts on social / technology / employment issues I am interested in here: http://societyredesigned.com/


The Knife (this blog) will be just about programming...