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
//Detect when tableview is updating | |
[CATransaction begin]; | |
[CATransaction setCompletionBlock:^{ | |
// animation has finished | |
}]; | |
[tableView beginUpdates]; | |
// do some work |
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
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate(BOOL)decelerate { | |
if (decelerate == NO) { | |
[self autoAdjustScrollToTop]; | |
} | |
} | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | |
[self autoAdjustScrollToTop]; | |
} | |
- (void)autoAdjustScrollToTop { | |
// compare the top two visible rows to the current content offset |
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*)imageWithBorderFromImage:(UIImage*)source; | |
{ | |
CGSize size = [source size]; | |
UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width, size.height+20), NO, 0.0); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
[source drawInRect:CGRectMake(0, 20, size.width, 44)]; | |
CGContextFillRect(context, CGRectMake(0, 0, size.width, 20)); |
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
@property (strong, nonatomic) AVCaptureDevice* device; | |
@property (strong, nonatomic) AVCaptureDeviceInput* input; | |
@property (strong, nonatomic) AVCaptureMetadataOutput* output; | |
@property (strong, nonatomic) AVCaptureSession* session; | |
@property (strong, nonatomic) AVCaptureVideoPreviewLayer* preview; | |
@property (strong, nonatomic) AVCaptureStillImageOutput* imgIO; | |
self.session = [[AVCaptureSession alloc] init]; | |
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; | |
NSError *error = 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
CGRect frame = [self.view frame]; | |
CGPoint topLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMinY(frame)); | |
CGPoint topRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMinY(frame)); | |
CGPoint bottomLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMaxY(frame)); | |
CGPoint bottomRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame)); | |
//If you need those coordinates in a particular view, the first line should be something like | |
CGRect frame = [self.view convertRect:[self.view bounds] toView:someOtherView]; |
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
[[UINavigationBar appearance] setTintColor:[UIColor grayColor]]; | |
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; // Takes out title | |
UIImage *backButtonImage = [UIImage imageNamed:@"BackArrowDark.png"]; | |
if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) { | |
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage]; | |
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage]; | |
} else { | |
int imageSize = 21; // REPLACE WITH YOUR IMAGE WIDTH |
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
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; | |
[rotationAnimation setRepeatCount:MAXFLOAT]; | |
[rotationAnimation setDuration:0.2]; | |
[rotationAnimation setAutoreverses:YES]; | |
[rotationAnimation setFromValue:@(M_PI / 25.0)]; | |
[rotationAnimation setToValue:@(-M_PI/ 25.0)]; | |
[someview.layer addAnimation:rotationAnimation forKey:@"wiggle"]; |
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
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section | |
{ | |
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] init]; | |
[headerView.contentView addSubview:self.someView]; | |
return headerView; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { | |
return CGRectGetHeight(self.someView.frame); //play around with this value |
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
Basic QuartzCore Framework Animations | |
//shrinking - scaling | |
CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; | |
shrink.toValue = [NSNumber numberWithDouble:0.9]; | |
shrink.duration = 0.5; | |
shrink.delegate = self; | |
[[targetView layer] addAnimation:shrink forKey:@"shrink"]; | |
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
//I created a typedef for a block: | |
typedef void (^animationCompletionBlock)(void); | |
// And a key that I use to add a block to an animation: | |
#define kAnimationCompletionBlock @"animationCompletionBlock" | |
// Then, if I want to run animation completion code after a CAAnimation finishes, I set myself as the delegate of the animation, and add a block of code to the animation using setValue:forKey: | |
animationCompletionBlock theBlock = ^void(void) | |
{ |