Skip to content

Instantly share code, notes, and snippets.

View psobko's full-sized avatar

Piotrek Sobkowski psobko

View GitHub Profile
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"];
- (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
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"];
[[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
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];
@psobko
psobko / new_gist_file
Created October 31, 2013 19:54
Rough VIdeoPreview+Image Capture from AVCaptureSession
@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;
@psobko
psobko / UIImage+BottomBorder
Created October 30, 2013 16:51
Add a bottom border to a UIImage
- (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));
- (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
@psobko
psobko / UITableView
Created October 29, 2013 19:15
UITableView
//Detect when tableview is updating
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// animation has finished
}];
[tableView beginUpdates];
// do some work
@psobko
psobko / Preprocessor Macros
Created October 28, 2013 17:09
Preprocessor Macros
//http://www.tutorialspoint.com/cprogramming/c_preprocessors.htm
#define Substitutes a preprocessor macro
#include Inserts a particular header from another file
#undef Undefines a preprocessor macro
#ifdef Returns true if this macro is defined
#ifndef Returns true if this macro is not defined
#if Tests if a compile time condition is true
#else The alternative for #if
#elif #else an #if in one statement