Skip to content

Instantly share code, notes, and snippets.

View pratikshabhisikar's full-sized avatar

Pratiksha Bhisikar pratikshabhisikar

View GitHub Profile
@pratikshabhisikar
pratikshabhisikar / gist:1149100
Created August 16, 2011 13:43
DogDelegate.h
@class Dog;
@protocol DogDelegate <NSObject>
@optional
-(void) dogWillStartBarking:(Dog *) aDog;
-(void) dogDidFinishBarking:(Dog *) aDog;
@end
@pratikshabhisikar
pratikshabhisikar / gist:1149147
Created August 16, 2011 13:57
DelegateDemo.m
- (void)viewDidLoad {
dog = [[Dog alloc] init];
dog.delegate = self;
[dog bark];
[super viewDidLoad];
}
@pratikshabhisikar
pratikshabhisikar / gist:1153829
Created August 18, 2011 10:57
Creating New Thread
-(IBAction) selectRegion:(id) sender
{
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
}
- (void)threadStartAnimating:(id)data
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread sleepForTimeInterval:1.0];
@pratikshabhisikar
pratikshabhisikar / gist:1153942
Created August 18, 2011 12:17
Scheduling NSRunLoop
/**
Schedules timer on the spinner thread.
*/
-(void) scheduleSpinner {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTimer *spinnerTimer = [NSTimer scheduledTimerWithTimeInterval:SPIN_FIRE_INTERVAL target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
BOOL isMainThread = [NSThread isMainThread];
@pratikshabhisikar
pratikshabhisikar / gist:1156586
Created August 19, 2011 11:10
Lazy Way to dismiss Modal View Controllers
// First Lazy method.
ViewControllerA *controllerA = self.parentViewController;
[controllerA.parentViewController dismissModalViewControllerAnimated:YES];
// Second Lazier Method
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
@pratikshabhisikar
pratikshabhisikar / gist:1170833
Created August 25, 2011 14:49
UIWebview Lazy Loading.
-(void) scrollEffectInDirection:(ScrollDirection) direction{
ContentView *previousPageView = (ContentView *)[self.pageScrollView viewWithTag:kPreviousPageTag];
ContentView *currentPageView = (ContentView *)[self.pageScrollView viewWithTag:kCurrentPageTag];
ContentView *nextPageView = (ContentView *)[self.pageScrollView viewWithTag:kNextPageTag];
switch (direction) {
case kScrollDirectionNone:
[self fillPageView:currentPageView withPageNumber:self.currentPage.pageNumber];
[self fillPageView:previousPageView withPageNumber:self.currentPage.pageNumber - 1];
[self fillPageView:nextPageView withPageNumber:self.currentPage.pageNumber + 1];
@pratikshabhisikar
pratikshabhisikar / gist:1172830
Created August 26, 2011 06:30
Dynamic UILabel Size
UIFont *labelFont = [UIFont fontWithName:fontName size:fontSize];
label.font = labelFont;
CGSize labelSize = [label.text sizeWithFont:label.font];
label.frame.size = labelSize;
@pratikshabhisikar
pratikshabhisikar / gist:1173386
Created August 26, 2011 13:22
UIView Flip Animation
[UIView beginAnimations:@"FlipAnimation" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myFirstDrillDownView cache:NO];
[UIView setAnimationBeginsFromCurrentState:YES];
[myFirstDrillDownView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
@pratikshabhisikar
pratikshabhisikar / gist:1173427
Created August 26, 2011 13:43
Card Flip Animation
-(void) show {
[UIView beginAnimations:[NSString stringWithFormat:@"%d", _serialNumber] context:nil];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[self addSubview:_frontView];
@pratikshabhisikar
pratikshabhisikar / gist:1183604
Created August 31, 2011 14:02
Detecting Left and Right scroll in UIScrollView with paging enabled.
typedef enum {
kScrollDirectionLeft = -1,
kScrollDirectionNone,
kScrollDirectionRight
}ScrollDirection;
-(void) scrollEffectInDirection:(ScrollDirection) direction{
ContentView *previousPageView = (ContentView *)[self.pageScrollView viewWithTag:kPreviousPageTag];
ContentView *currentPageView = (ContentView *)[self.pageScrollView viewWithTag:kCurrentPageTag];
ContentView *nextPageView = (ContentView *)[self.pageScrollView viewWithTag:kNextPageTag];