Drawing erase helperPosted in iPhone MonoTouch development on January 19, 2011 by Pavel Sich 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. Don't you just love MonoTouch?Posted in iPhone MonoTouch development on January 06, 2011 by Pavel Sich 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!
MonoTouch UITableViewController transparent backgroundPosted in iPhone MonoTouch development on December 07, 2010 by Pavel Sich 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!
Monotouch infinite loop image scroll viewPosted in iPhone MonoTouch development on November 11, 2010 by Pavel Sich 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. Monotouch set status bar hiddenPosted in iPhone MonoTouch development on November 01, 2010 by Pavel Sich 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);
MonoTouch TapGesture without gesture recognizerPosted in iPhone MonoTouch development on October 21, 2010 by Pavel Sich 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 ...]. MonoTouch PerformSelector HelperPosted in iPhone MonoTouch development on September 30, 2010 by Pavel Sich 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"? iOS SDK cannot installPosted in Apps on September 24, 2010 by Pavel Sich 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) function volumeCheck() { return true; } 5. close the text edit and save the file 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).
Show ModalViewController just after another onePosted in iPhone Objective C development on August 11, 2010 by Pavel Sich 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!
Tap gesture without UITapGestureRecognizerPosted in iPhone Objective C development on August 05, 2010 by Pavel Sich 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.
- (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!
|
