Sunday, 05 September 2010

Touch4Apps Blog | posts about iPhone : iPad : iPod app development

You might come to a problem when you need to show new modal view controller just after another has been dismissed. And you want to preserve the animation even on dismiss.

Unfortunately it is not possible to call:

[self dismissModalViewControllerAnimated:TRUE];
 
[self presentModalViewController:picker animated:YES];
 

 

 As the second one will never show up.

@performSelector is the cure for our problem, just delay the call to the other modal view controller a bit:

[self dismissModalViewControllerAnimated:TRUE];
 
// schedule the open mail composer in a little delay
[self performSelector:@selector(sendMail) withObject:nil afterDelay: 0.45];

 

 Where in the sendMail function we call the obvious presentModalViewController on the mail picker controller.

Happy coding!

 

 

Ever needed to handle the tap event but needed to distinguish between tap and double tap? I guess everybody sometimes get to such issue and surprisingly prior iOS 4 there is no simple way how to do it.

With iOS4 you just call UITapGestureRecognizer and you are ready to go, so how to do it with version prior iOS4? Here you go:

 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	NSUInteger numTaps = [[touches anyObject] tapCount];
 
	if (numTaps < 2) 
	{
		[self performSelector:@selector(doSomeSingleTapAction) withObject:nil afterDelay: 0.25];
 
		[self.nextResponder touchesEnded:touches withEvent:event];
	} 
     	else 
     	{
		if(numTaps == 2) 
          	{
			[NSObject cancelPreviousPerformRequestsWithTarget:self];
 
			[self performSelector:@selector(doSomeDblTapAction) withObject:nil afterDelay: 0.25];
		}		
 
	}
}

 

Happy coding!

 

When using affine transform to rotate views (UIIMageView in most cases, right?) for example like this:

CGAffineTransform transform = 
	CGAffineTransformMakeRotation(-b->GetAngle());
 
oneView.transform = transform;

 

 Make sure you then translate the object using its center property and not using the frame property, as frame is already affected by the affine transform and your image would be corrupted.

Happy coding!

 

Had the need to show the datetime in the toolbar next to the touch button. Just adding the UILabel as subview to the UIToolbar makes the app to crash. But there is a solution:

 

1
2
3
4
5
6
7
8
9
UILabel* timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 240, 20)];
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];
 
// add your text here, using NSDateFormatter for example
timeLabel.text = @""; 
 
// create the bar button item where we specify the label as a view to use to init with     
UIBarButtonItem *dateTimeText = [[UIBarButtonItem alloc] initWithCustomView:timeLabel];

 

Happy coding!

 

When setting up an image to the UIImageView for dbl resolution for retina display make sure to set the image after setting the frame of the view as initWithImage on UIImageView does not work properly.

 

1
2
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[backgroundImageView setImage:[UIImage imageNamed:@"bg-wall01.jpg"]];

 

Where in resources we have file named " This e-mail address is being protected from spambots. You need JavaScript enabled to view it ", iOS4 does the trick for us to set the image scale to 2.0 for us (or rather 0.5 in fact).

Happy coding!