Skip to content

Instantly share code, notes, and snippets.

@taberh
taberh / gist:2389644
Created April 15, 2012 03:04
iphone uiimagepickercontroller subviews structure
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIView * previewView = [[[[[[[[[[self.picker.view // UILayoutContainerView
subviews] objectAtIndex:0] // UINavigationTransitionView
subviews] objectAtIndex:0] // UIViewControllerWrapperView
subviews] objectAtIndex:0] // UIView
subviews] objectAtIndex:0] // PLCameraView
subviews] objectAtIndex:0]; // PLPreviewView
[previewView touchesBegan:touches withEvent:event];
}
@taberh
taberh / fineViewWithName
Created April 15, 2012 03:08
find view with view name
-(UIView *)findView:(UIView *)view withName:(NSString *)name{
Class cl = [view class];
NSString *desc = [cl description];
if ([desc compare:name] == NSOrderedSame)
return view;
for (int i = 0; i < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
@taberh
taberh / imageFromView
Created July 2, 2012 03:25
get UIImage object in the UIView
+ (UIImage *)imageFromView:(UIView *)view
{
UIGraphicsBeginImageContext(view.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view layer] renderInContext:context];
UIImage *image = UIGraphicsGetImageFromImageContext();
UIGraphicsEndImageContext();
return image;
}
@taberh
taberh / gist:3031954
Created July 2, 2012 08:34
get bitmap from image
unsigned char *getBitmapFromImage(UIImage *image)
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace == NULL) {
fprintf(stderr, "Error allocating color space\n");
return NULL;
}
@taberh
taberh / gist:3161590
Created July 23, 2012 01:19
check jailbreak device for iPhone
BOOL isJailbreak()
{
int res = access("/var/mobile/Library/AddressBook/AddressBook.sqlitedb", F_OK);
if (res != 0)
return NO;
return YES;
}
@taberh
taberh / gist:3357386
Created August 15, 2012 07:32
get app infomation from itunes.apple.com
//HTTP POST - http://itunes.apple.com/lookup?id={appid}
//Result(JSON):
{
"resultCount":1,
"results": [
{
"kind":"software",
@taberh
taberh / gist:3365672
Created August 16, 2012 02:15
check ios app is first launch
#define LAST_LAUNCH_VERSION_KEY @"last_launch_version_of_application"
- (BOOL)isFirstLoad
{
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastLaunchVersion = [defaults objectForKey:LAST_LAUNCH_VERSION_KEY];
if (!lastLaunchVersion || ![lastLaunchVersion isEqualToString:currentVersion]) {
@taberh
taberh / gist:3607887
Created September 3, 2012 08:30
radians and degrees convert
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180 / M_PI;};
@taberh
taberh / gist:3689377
Created September 10, 2012 07:12
DLog
#ifdef DEBUG
# define DLog(...) NSLog(__VA_ARGS__)
#else
# define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
@taberh
taberh / gist:3719302
Created September 14, 2012 01:40
Use Core Graphics draw corner
void drawCorner(CGContextRef context, CGRect rect, float corner)
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM(context, corner, corner);
CGFloat fw = CGRectGetWidth(rect) / corner;
CGFloat fh = CGRectGetHeight(rect) / corner;
CGContextMoveToPoint(context, fw, fh/2);
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);