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
void (^doIt)(id retryBlk); | |
@weakify(self); | |
doIt = ^(id retryBlk){ | |
void (^retry)(id retryBlk) = retryBlk; | |
retry(retryBlk); | |
}; | |
doIt(doIt); |
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
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:self.recordedVideoFileURL options:nil]; | |
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset]; | |
gen.appliesPreferredTrackTransform = YES; | |
NSError *err = NULL; | |
CMTime cmTime = CMTimeMake(time, 1); | |
CGImageRef imgRef = [gen copyCGImageAtTime:cmTime actualTime:NULL error:&err]; | |
UIImage *img = [[UIImage alloc] initWithCGImage:imgRef]; | |
return img; |
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
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; |
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
// Context: A UILabel category/subclass. Otherwise replace "self"... | |
- (instancetype)clonedVersionWithText:(NSString *)text | |
{ | |
// Warning: Not necessarily complete, but a good start ;) | |
// Size & position | |
UILabel *clonedLbl = [[UILabel alloc] initWithFrame:self.frame]; | |
// Text |
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
for (NSString* family in [UIFont familyNames]) | |
{ | |
NSLog(@"%@", family); | |
for (NSString* name in [UIFont fontNamesForFamilyName: family]) | |
{ | |
NSLog(@" %@", name); | |
} | |
} |
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
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity | |
{ | |
// We're going to center the centermost item... | |
// Use the bounds to have the snap happen the minute drag stops. In other words use the current content offset (which = bounds.origin) instead of the proposed end offset (which takes velocity into account) | |
CGRect proposedRect = self.collectionView.bounds; | |
CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5f; | |
// Comment out if you want the collectionview simply stop at the center of an item while scrolling freely (ie take velocity into account) |
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
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView | |
{ | |
const CGFloat DECEL = 500; // pixels/second decrease in velocity per second. need to guess this | |
CGPoint vel = [self.panGestureRecognizer velocityInView:self.superview]; | |
if (vel.y > 0) return; | |
CGFloat bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height; | |
CGFloat distanceToBottom = scrollView.contentSize.height -bottomEdge; |
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
CGPoint scrollVelocity = [self.panGestureRecognizer velocityInView:self.superview]; | |
if (scrollVelocity.y > 0.0f) | |
NSLog(@"going down"); | |
else if (scrollVelocity.y < 0.0f) | |
NSLog(@"going up"); |
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
extension Double { | |
var km: Double { return self * 1_000.0 } | |
var m: Double { return self } | |
var cm: Double { return self / 100.0 } | |
var mm: Double { return self / 1_000.0 } | |
var ft: Double { return self / 3.28084 } | |
} | |
let oneInch = 25.4.mm | |
println("One inch is \(oneInch) meters") | |
// prints "One inch is 0.0254 meters" |