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"? UIImage ScaleToFitPosted in iPhone MonoTouch development on April 12, 2010 by Pavel Sich Sometimes the image provided by the UIImagePicker is not the right size, and putting it to the UIImageView is not enough as we do need to know the size it was being fit to.
UIGestureRecognizer using MonoTouchPosted in iPhone MonoTouch development on February 23, 2010 by Pavel Sich When implementing touch and gesture based interaction in your application, for example the swipe effect, you had to handle the TouchesMoved, TouchesBegan, TouchesEnded and TouchesCancelled events and handle the location of the finger and last location and so on, based on the quality of the algorithm it worked or not. With the new SDK and with the great support from MonoTouch team, its current version of MonoTouch implements the UIGestureRecognizer and UIGestureRecognizerDelegate and related classes - UITapGestureRecognizer, UISwipeGestureRecognizer, UIRotationGestureRecognizer, UIPinchGestureRecognizer, UILongPressGestureRecognizer, UIPanGestureRecognizer. Lets have a look and few simple steps to take advantage of these common gesture implementations on the iPhone/iPad. For the demonstration we will use the swipe gesture. First we need to have a view controller and define a Selector for the gesture recognizer. More on Selectors check the iPhone SDK, in general it is a special form of message. In MonoTouch Selectors can be consumed (fired from MonoTouch code) or exposed, being available to SDK functions and classes to be called from within. Lets have a look at the typical implementation:
Please note that the Selector is defined as a static access property returning the identification of the selector via its name (HandleSwipe). Next we need to define the gesture recognizer and its delegate and assign it to the view. We do this in the ViewDidLoad event of the controller implementation class.
Then we need our delegate class for the swipe recognizer:
And last and finally our handler for the swipe event:
Well, that is all and we are done. Happy coding!
|
