This file contains 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
#define DEGREES_RADIANS(angle) ((angle) / 180.0 * M_PI) | |
- (UIImage*) UIImageCrop:(UIImage *)img withRect:(CGRect)rect { | |
CGAffineTransform rectTransform; | |
switch (img.imageOrientation) | |
{ | |
case UIImageOrientationLeft: | |
rectTransform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(DEGREES_RADIANS(90)), 0, -img.size.height); | |
break; | |
case UIImageOrientationRight: |
This file contains 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
CGRect visibleRect = CGRectMake(0, 0, self.scrollView.contentSize.width, self.scrollView.contentSize.height); | |
CGRect centeredRect = CGRectMake(visibleRect.origin.x + visibleRect.size.width/2.0 - self.scrollView.frame.size.width/2.0, | |
visibleRect.origin.y + visibleRect.size.height/2.0 - self.scrollView.frame.size.height/2.0, | |
self.scrollView.frame.size.width, | |
self.scrollView.frame.size.height); | |
[self.scrollView scrollRectToVisible:centeredRect animated:NO]; |
This file contains 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 *start = [NSDate date]; | |
//process | |
NSDate *methodFinish = [NSDate date]; | |
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start]; | |
NSLog(@"Execution Time: %f", executionTime); |
This file contains 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
@interface UIImage (FixOrientation) | |
- (UIImage *)fixOrientation; | |
@end | |
@implementation UIImage (FixOrientation) | |
- (UIImage *)fixOrientation { | |
This file contains 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
// Method: vImageScaledImage:(UIImage*) sourceImage withSize:(CGSize) destSize | |
// Returns even better scaling than drawing to a context with kCGInterpolationHigh. | |
// This employs the vImage routines in Accelerate.framework. | |
// For more information about vImage, see https://developer.apple.com/library/mac/#documentation/performance/Conceptual/vImage/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001001-CH201-TPXREF101 | |
// Large quantities of memory are manually allocated and (hopefully) freed here. Test your application for leaks before and after using this method. | |
+ (UIImage*) vImageScaledImage:(UIImage*) sourceImage withSize:(CGSize) destSize; | |
{ | |
UIImage *destImage = nil; | |
if (sourceImage) |
This file contains 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 CustomOperation | |
- (instancetype)init { | |
self = [super init]; | |
if (self) { | |
} | |
return self; | |
} |
This file contains 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
- (CGFloat)getTransformScale { | |
CGAffineTransform transform = self.transform; | |
CGFloat scale = sqrt(transform.a*transform.a + transform.c*transform.c); | |
return scale; | |
} | |
- (CGFloat)getTransformAngle { | |
CGAffineTransform transform = self.transform; | |
CGFloat angle = atan2(transform.b, transform.a); | |
return angle; |
This file contains 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
static void * const MyClassKVOContext = (void*)&MyClassKVOContext; | |
- (void)addContext { | |
[object addObserver:self forKeyPath:NSStringFromSelector(@selector(property)) options:0 context:MyClassKVOContext]; | |
} | |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | |
{ | |
if (context == MyClassKVOContext) { | |
if ([keyPath isEqualToString:NSStringFromSelector(@selector(property))]) { |
This file contains 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
+ (NSString *)createUniqueId { | |
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault); | |
CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, cfuuid); | |
CFRelease(cfuuid); | |
return CFBridgingRelease(string); | |
} |
This file contains 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
static inline NSString * ImageCacheKeyFromURLRequest(NSURLRequest *request) { | |
return [[request URL] absoluteString]; | |
} |
OlderNewer