Monday, 21 May 2012

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

For one of our app we needed drawing technique that would delete the image in graphics context based on the user input and act like a erase rubber.

Of course there is again everything needed in MonoTouch to do the job.

Tags ,
AddThis Social Bookmark Button

Objective C sure is nice and powerful, but don't you just love stuff like:

 

this.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Close", UIBarButtonItemStyle.Done, (s, e) => popoverContent.DismissModalViewControllerAnimated(true));

 

(Inside UIViewController class that is being presented in UINavigationController)

Happy coding!

 

AddThis Social Bookmark Button

Just came across a problem to have UITableViewController on a custom texture, wanted and needed to have the nice rounded corners as well and found out it is not that straightforward to set the background color to transparent in case that running on iPad (3.2 and 4.2 as well).

So here is a little code snippet that does the trick.

 

// create the UITableViewController
SettingTableViewController tableController = new SettingTableViewController(UITableViewStyle.Grouped);
 
// set its color to transparent as well, as this is needed, this is the first layer of the setup
tableController.View.BackgroundColor = UIColor.Clear;
tableController.View.Frame = new RectangleF(12, 101, 280, 98);
 
// create a dummy view for the underlaying view			
UIView view = new UIView();
view.Frame = tableController.View.Frame;
 
// make its color transparent as well
view.BackgroundColor = UIColor.Clear;
 
// and now the little trick, get to the core of the view hierarchy and set the view from the original UIImageView, in which the UITableView of the controller lays, to our custom transparent view
((UITableView)tableController.View).BackgroundView = view;
 
 

 

Happy coding!

 

AddThis Social Bookmark Button

One of the clients wanted in the app a little feature for a menu system, something like a karusel, where specific menu items will be scrolled from side to side with a touch in an infinite loop.

I found out that it can be possible to do with a simple tweak to UIScrollView, handing the

scrollViewDidEndDecelerating from the UIScrollViewDelegate.

 

Guys from Monotouch team made the great job on this (as usual) and we have the delegate already available via built-in events, in this case DecelerationEnded.

So lets have a look at the implementation of the UIViewController class of some view, note we are adding the UI from the code, not from the nib file, just for simplicity. View has UIScrollView item and loads some images, last image is placed as the first one, then all images in the order and then first image as the last one.

Then the event for DecelerationEnded is handled to actually swap the position (fast - no animation) so user does not find out. For added more touch, the paging is enabled and of course the scroller is hidden, so it is not visible to the user where in the scrolling position he actually is.

AddThis Social Bookmark Button

If you ever needed to set the status bar hidden in Monotouch App, and wanted to do it properly for code that runs backward compatible on OS 3.X while developing on iOS SDK 4.X and also for newer devices, here is the answer:

 

if (UIApplication.SharedApplication.RespondsToSelector (new Selector ("setStatusBarHidden: withAnimation:")))
	UIApplication.SharedApplication.SetStatusBarHidden (true, UIStatusBarAnimation.Fade);
else
	UIApplication.SharedApplication.SetStatusBarHidden (true, true);
 

 


 

 

AddThis Social Bookmark Button

Few weeks ago I wrote a post about how to handle tap gesture on iOS prior gesture recognizers. In Objective-C there is simple trick with [self.nextResponder ...] and then [NSObject cancelPreviousPerformRequestWithTarget ...].

In MonoTouch NextResponder on Controller object is read only for some reason, and therefore cannot be used to implement this technique in a simple way. So a bit more coding is needed.

AddThis Social Bookmark Button

It is a common issue in MonoTouch that function performSelector with delay attribute is not working out of the box, you need to fiddle with the NSRunLoop as per the comment from Geoff Norton from Novell:

PerformSelector with delay works fine, given that you understand its
restrictions.  It only works on threads with a NSRunLoop, and is completed
async.

So what to do, and do not want to or cannot get into the NSRunLoop "issue"?

AddThis Social Bookmark Button

Ever had the problem installing any mpkg installer? Happened to me today, I received for no apparent reason information that JavaScript check failed during the iOS SDK installation. Was not able to resolve in a normal way, so had to hack a bit, here it is how (BTW works for any mpkg file, not only Xcode with iOS SDK).

1. extract the mpkg package with XAR (xar -xf path_to_your_installer.mpkg)
2. locate the dist file in the  content subdirectory (iPhoneSDKSL.dist in this case)
3. open it in some text editor (vi will be fine in this case)
4. check the volume check function there and just change to JS code to return true:

function volumeCheck()
{
return true;
}

function volumeCheck() { return true; }

5. close the text edit and save the file
6. repackage the mpkg back with XAR (xar -cf iOSDSDKInstall.mpkg path_to_the_extracted_location)
7. run the new package and all is well

BTW. if you use PathFinder app you can save lots of manual work, just right click the MPKG, select show content, then click the dist file and select open with and edit it in place. save it and that is it, PathFinder will repackage for you.

Happy hacking (in this case). 

 

AddThis Social Bookmark Button

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!

 

 

AddThis Social Bookmark Button

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!

 

AddThis Social Bookmark Button