Skip to content

Instantly share code, notes, and snippets.

View abbeyjackson's full-sized avatar
😬
Let's cross our fingers and hope Xcode builds!

Abbey Jackson abbeyjackson

😬
Let's cross our fingers and hope Xcode builds!
View GitHub Profile
@abbeyjackson
abbeyjackson / sharedInstance Singleton
Last active May 4, 2016 13:35
sharedInstance singleton
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@abbeyjackson
abbeyjackson / Explode completed tetris blocks
Last active September 13, 2015 04:54
1:09 on Stanford iOS Lecture 8 https://youtu.be/aS6PBmBAP1g explode completed blocks, like tetris
- (BOOL)removeCompletedRows
{
NSMutableArray *dropsToRemove = [[NSMutableArary alloc] init];
for (CGFloat y = self.gameView.bounds.size.height-DROP_SIZE.height/2; y > 0; y -= DROP_SIZE.height)
{
BOOL rowIsComplete = YES;
NSMutableArray *dropsFound = [[NSMutableArray allc] init];
for (CGFloat x = DROP_SIZE.width/2; x <- self.gameView.bounds.size.witdh-DROP_SIZE.width/2; x += DROP_SIZE.width)
{
UIView *hitView = [self.gameView hitTest:(CGPointMake(x, y) withEvent:NULL];
@abbeyjackson
abbeyjackson / Slow scrolling
Last active September 13, 2015 04:54
However, be careful with cell layer properties such as ​`cornerRadius`​ or ​`maskLayer`​ because it could slow your scroll down this would cache the layer as a bitmap and uses the bitmap during the animation instead of keep drawing on every frame change
layer.shouldRasterize = true
layer.rasterizationScale = [UIScreen mainScreen].scale
@abbeyjackson
abbeyjackson / Paged UIScrollView
Last active September 13, 2015 04:53
How to make a paged scrollview from images and text. Set up all outlets in addition to this. This is using objects for each "page" which contain two NSString properties and one UIImage property. Search: Announcement Slider, Image Slider, Paged Slider, Scrollview Slider, UIScrollview.
- (void)viewDidLoad {
[super viewDidLoad];
self.array = [self configureArray];
for (int i = 0; i < self.array.count; i++) {
CGRect frame;
frame.origin.x = self.view.frame.size.width * i;
frame.origin.y = 0;
@abbeyjackson
abbeyjackson / Container View Controller
Created September 15, 2015 06:01
This is the code for the Container View Controller when setting up a UIContainerView From http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
#import "ContainerViewController.h"
#define SegueIdentifierFirst @"embedFirst"
#define SegueIdentifierSecond @"embedSecond"
@interface ContainerViewController ()
@property (strong, nonatomic) NSString *currentSegueIdentifier;
@end
@implementation ContainerViewController
@abbeyjackson
abbeyjackson / Log UI Elements
Created September 16, 2015 16:59
NSLog / print out what UI element you tap. For finding what code / method / function belongs to what element. From Aryan Ghassemi in ios-dev slack
- (void)viewDidLoad {
[super viewDidLoad];
[self addGesture:self.view];
}
- (void)addGesture:(UIView *)aView {
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didDetectClick:)];
[aView addGestureRecognizer:gesture];
for (UIView *subView in aView.subviews) {
@abbeyjackson
abbeyjackson / indexPath of cell
Created September 29, 2015 19:04
get indexPath (index path) of current cell
UITableViewCell *cell = sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
@abbeyjackson
abbeyjackson / threading
Created September 29, 2015 20:26
synchronous asynchronous background main thread and queue (usually just use "queue" as variable name, descriptive names below only for clarity)
// get global queue
dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// create serial background queue
dispatch_queue_t newQueue = dispatch_queue_create("com.domain.app.queuename", 0);
// dispatch asynchronously to a specific thread
dispatch_async(queueName, ^{
// the slow stuff to be done in the background
});
@abbeyjackson
abbeyjackson / custom Tab Bar using tags
Last active October 16, 2015 20:30
multiple buttons and one delegate function, using tags and protocol, in Swift
in UIViewController:
import UIKit
class tempViewController: UIView {
var array : NSArray
func buttonPressed(navigationBar: ScrollBar, sender: UIButton) {
switch sender.tag {
case 0:
@abbeyjackson
abbeyjackson / Custom TabBar multiple IBAction, no tags
Last active October 16, 2015 20:34
Multiple buttons with same protocol - delegate function, using multiple IBActions instead of tags
in tabBar.swift
protocol TabBarDelegate {
func buttonPressed(tabBar: TabBar, section: SectionType)
}
var delegate: TabBarDelegate?
@IBAction func buttonAPressed(sender: UIButton){
delegate?.buttonPressed(self, section: SectionType.caseA)