May 17, 2010, 8:59 pm
For one of my projects on the iPad I wanted to popup a detail window out of an existing image view, using some animation while popping up. CoreAnimation was the way to go, but I was facing difficulties to:
a) find out how to do it and
b) get it working.
The animation should combine movement (from the location of the clicked image to the location where the popup is shown), scaling (from the image size to the popup size) and rotation (for a nice effect). Google searches delivered bits and pieces, the best sample I found was MFFlip from Mike Lee. This didn’t include scaling and movement like I wanted it, so I added this and then packed it up nicely into a single class ViewFlipper with a single factory method that takes 2 views as parameters and does all the calculations and animation. The ViewFlipper class can be included without further dependencies into any project, except that you need to include the QuartzCore framework.
I’ve created a little sample iPad program around it that you can download here. I’ve put some documentation in the code that describes the what goes on inside. I hope this is useful for others who are struggling with this too.
Note: initially I kept having trouble with all of the examples I found, it turned out this was caused by the fact that I had one view with 3 subviews: a UITableView covering the entire view, the imageView and popupView (which were shown above the UITableView). I managed to solve this by moving the imageView and popupView onto a view of its own. I gave this extra view a transparent background, so that the underlying UITableView was still visible. This extra view also has the advantage that you can catch touch events on it which you can use to popdown the popup.
July 11, 2009, 3:16 pm
MPoD is retrieving cover art for the currently playing song from Amazon the AWS (Amazon Web Services). From August 15 onwards, all requests made will have to be signed using a secret key that is attached to the registered AWSAccessKeyId. Searching on Google, I found various helpful bits, especially on the learn amazon web services blog. But I didn’t find a ready made implementation that I could use directly from my code.
Based on what I found I created a helper class AWSRequestSigner, that takes a dictionary of parameters to pass to the webservice, and returns a ready made NSURL object that can be used in an NSURLRequest object as in the following example:
NSURL *url = [AWSRequestSigner urlForParameterDict:[NSDictionary dictionaryWithObjectsAndKeys:
@"Sea Of Tears", @"Title",
@"Eilen Jewell", @"Artist",
@"ItemSearch", @"Operation",
@"Images", @"ResponseGroup",
@"Music", @"SearchIndex",
@"AWSECommerceService", @"Service",
nil]];
To look at the source code for the AWSRequestSigner class, download it here and open it in XCode.
November 15, 2008, 10:53 pm
Many developers have been facing issues with building iphone applications using distribution profiles (AdHoc and AppStore). Often the correct distribution profiles don’t appear in the build settings in XCode.
I have been struggling with this for quite some time as well, but as of late I seem to have found a method of working that always does the trick. What it comes down to, is that when you want to change the build settings, as well as when you want to build a distribution version, you need to make sure that a device (iPhone, iPod Touch) is connected to your Mac. If you don’t connect it, there’s a good chance that the build profiles don’t show up in the build settings. Connecting the device and restarting XCode usually fixes this.
The practice I’m using currently, is that whenever I want to build for testing in the iPhone simulator I make sure no device is connected, and when a build is destined for a device I make sure that a device is actually connected. I make it a habit to connect or disconnect the device (depending on the build target), and restart XCode. This is a bit of a hassle, but at least it gives me predictable results.
November 9, 2008, 9:30 am
Recently the successful iPhone applications Trein and iNap realized a tight integration, in that you can activate iNap directly from Trein. How to create the integration on the side of the ‘receiving’ application, iNap in this case, is described in the iPhone SDK example ‘Launch Me’.
When integrating applications, you typically want to pass data from one to the other, in this post I’ll describe how the incoming parameters can easily be extracted in the receiving application.
The receiving application will register itself in the OS (for details see the ‘Launch Me’ example), and the result is that it can be activated from another application or from a hyperlink in a webpage. An example of a url that activates another application is:
myapp://myapp?latitude=51.3&longitude=5.2&title=middle of nowhere
In the receiving application the method - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url will be called on the application delegate object, and in this method you need to extract the parameters from the URL. The following code shows how to do that with minimal code. Like Apple’s example, it does a lot of checking to prevent undesired usage, in this case the url parameters must meet the exact specifications (i.e. no missing parameters, no extra parameters) otherwise the request will be ignored.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
// You should be extremely careful when handling URL requests.
// You must take steps to validate the URL before handling it.
// If any of the validations fails, bail out returning NO.
if (!url) {
// The URL is nil. There's nothing more to do.
return NO;
}
// Split the url into two sections, one section with the base url and one with the parameters.
NSArray *urlSections = [[url absoluteString] componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"?"]];
// Check that you actually got a base section and a parameter section.
if ([urlSections count] != 2) {
return NO;
}
// Check that the base part of the url is what you expect it to be.
if (![[urlSections objectAtIndex:0] isEqualToString:@"myapp://myapp"]) {
return NO;
}
// Split up the parameter section into a parameter Array.
NSArray *parameterArray = [[urlSections objectAtIndex:1] componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"&="]];
NSEnumerator *parameterEnum = [parameterArray objectEnumerator];
NSString *parameter, *value;
// The parameters values that we are expecting.
NSString *latitude = nil, *longitude = nil, *title = nil;
// Run through the array of parameters.
while (parameter = [parameterEnum nextObject]) {
// Get the value that goes with this parameter, and if it is missing break.
if ((value = [parameterEnum nextObject]) == nil)
break;
// Check the parameter value against the parameters that you support/expect,
// and assign the matching value to the right variable.
if ([parameter isEqualToString:@"latitude"])
latitude = value;
else if ([parameter isEqualToString:@"longitude"])
longitude = value;
else if ([parameter isEqualToString:@"title"])
title = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
else {
// An unexpected parameter was passed, bail out.
latitude = nil;
longitude = nil;
title = nil;
break;
}
}
// Check if we got all parameters (in this case all are mandatory), if not bail out.
if (latitude == nil || longitude == nil || title == nil) {
return NO;
}
// Use the parameters to do your thing.
CLLocation *location = [[[CLLocation alloc]
initWithLatitude:[latitude doubleValue]
longitude:[longitude doubleValue]] autorelease];
[someObject activateDestination:title location:location];
return YES;
}