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!
Affine Transform and UIView's Frame vs. Center propertyPosted in iPhone Objective C development on August 05, 2010 by Pavel Sich 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!
Add UILabel to UIToolbarPosted in iPhone Objective C development on August 05, 2010 by Pavel Sich 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:
Happy coding!
UIImageView retinaPosted in iPhone Objective C development on July 16, 2010 by Pavel Sich 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.
Where in resources we have file named "bg-wall01@2x.jpg", iOS4 does the trick for us to set the image scale to 2.0 for us (or rather 0.5 in fact). Happy coding!
Objective C - datetime currentPosted in iPhone Objective C development on May 26, 2010 by Pavel Sich No more need to explain. How to get the current datetime and have it stored.
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!
|
