Archive for the ‘iOS’ Category
How to trigger UIButton with UITapGestureRecognizer
To trigger UIButton touch action within a view that has a UITapGestureRecognizer, you have to implement the the UIGestureRecognizerDelegate protocol and its method -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.controlSubview.superview != nil) {
if ([touch.view isDescendantOfView:self.controlSubview]) {
// we touched our control surface
return NO; // ignore the touch
}
}
return YES;
// handle the touch
}
or
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UIButton class]]){
return FALSE;
}
return TRUE;
}
How to flip UIImage
UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];
UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
Constants:
UIImageOrientation
Specifies the possible orientations of an image.
typedef enum {
UIImageOrientationUp,
UIImageOrientationDown, // 180 deg rotation
UIImageOrientationLeft, // 90 deg CCW
UIImageOrientationRight, // 90 deg CW
UIImageOrientationUpMirrored, // as above but image mirrored along
// other axis. horizontal flip
UIImageOrientationDownMirrored, // horizontal flip
UIImageOrientationLeftMirrored, // vertical flip
UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;
Read More at ios developer reference
How to convert NSString to BOOL, Int, Float, Double, Long
Posted by: admin in iOS, NSString, Objective C, String on June 25th, 2011
- Converting NSString to Bool
[NSString_Instance boolValue];
- Converting NSString to Integer
[NSString_Instance intValue];
or
[NSString_Instance integerValue];
- Converting NSString to Float
[NSString_Instance floatValue];
- Converting NSString to Double
[NSString_Instance doubleValue];
- Converting NSString to Long
[NSString_Instance longLongValue];
How to check if file is exists in iOS
Posted by: admin in iOS, NSFileManager on June 25th, 2011
use the NSFileManager class.
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:@”filename”];