This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Override this method in any class to get a pretty list of | |
// all methods that are being called - very useful. | |
// Try it on the AppDelegate for example | |
-(BOOL)respondsToSelector:(SEL)aSelector { | |
printf("The spy says: %s\n", [NSStringFromSelector(aSelector) UTF8String]); | |
return [super respondsToSelector:(aSelector)]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make a picture browser, just like in the Photo app | |
// **With only six additional lines of code!** | |
// in viewDidLoad: | |
self.tableView.transform = CGAffineTransformMakeRotation(-M_PI/2); // turn the table 90° anti-clockwise | |
self.tableView.showsVerticalScrollIndicator = NO; | |
self.tableView.pagingEnabled = YES; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// override this method to get a great log output | |
// to show how the view is resized when rotating, | |
// calling sizeToFit and other methods that affect the frame | |
- (void) setFrame:(CGRect)frame { | |
[super setFrame:frame]; | |
NSLog(@"%@ - %@", NSStringFromSelector(_cmd), NSStringFromCGRect(frame)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSDate *) lastMondayBeforeDate:(NSDate*)timeStamp { | |
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSDateComponents *comps = | |
[gregorian components:NSWeekdayCalendarUnit fromDate:timeStamp]; | |
NSInteger weekday = [comps weekday]; | |
weekday = weekday==1 ? 6 : weekday-2; // start with 0 on Monday rather than 1 on Sunday | |
NSTimeInterval secondsSinceMondayMidnight = | |
(NSUInteger) [timeStamp timeIntervalSince1970] % 60*60*24 + | |
weekday * 60*60*24; | |
return [timeStamp dateByAddingTimeInterval:-secondsSinceMondayMidnight]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSObject (PerformBlockAfterDelay) | |
- (void)performBlock:(void (^)(void))block | |
afterDelay:(NSTimeInterval)delay | |
{ | |
block = [[block copy] autorelease]; | |
[self performSelector:@selector(fireBlockAfterDelay:) | |
withObject:block | |
afterDelay:delay]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create a fancy shadow around the frontView. | |
* | |
* Note: UIBezierPath needed because shadows are evil. If you don't use the path, you might not | |
* not notice a difference at first, but the keen eye will (even on an iPhone 4S) observe that | |
* the interface rotation _WILL_ lag slightly and feel less fluid than with the path. | |
*/ | |
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.frontView.bounds]; | |
self.frontView.layer.masksToBounds = NO; | |
self.frontView.layer.shadowColor = [UIColor blackColor].CGColor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The main localization class that does the hard work | |
-(NSString *) localized:(NSString *) key | |
{ | |
// langCode should be set as a global variable somewhere | |
NSString *path = [[NSBundle mainBundle] pathForResource:langCode ofType:@"lproj"]; | |
NSBundle* languageBundle = [NSBundle bundleWithPath:path]; | |
return [languageBundle localizedStringForKey:key value:@"" table:nil];; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage*) maskImage:(UIImage *)im withMask:(UIImage *)maskImage { | |
CGImageRef maskRef = maskImage.CGImage; | |
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), | |
CGImageGetHeight(maskRef), | |
CGImageGetBitsPerComponent(maskRef), | |
CGImageGetBitsPerPixel(maskRef), | |
CGImageGetBytesPerRow(maskRef), | |
CGImageGetDataProvider(maskRef), NULL, false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INSERT CELL ANIMATION SNIPPET HERE | |
- (void)startQuivering | |
{ | |
CABasicAnimation *quiverAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; | |
float startAngle = (-2) * M_PI/180.0; | |
float stopAngle = -startAngle; | |
quiverAnim.fromValue = [NSNumber numberWithFloat:startAngle]; | |
quiverAnim.toValue = [NSNumber numberWithFloat:3 * stopAngle]; | |
quiverAnim.autoreverses = YES; | |
quiverAnim.duration = 0.2; |
OlderNewer