Skip to content

Instantly share code, notes, and snippets.

@edwardean
edwardean / DismissGravity.h
Created January 6, 2017 09:46 — forked from andkon/DismissGravity.h
Animated transitions and UIKit Dynamics
@interface DismissGravity : NSObject <UIViewControllerAnimatedTransitioning>
@property (strong, nonatomic) UIDynamicAnimator *animator;
@edwardean
edwardean / gist:e2dfd515280dfb49891f2f1c0b678cdf
Created January 5, 2017 01:46
Fast int to NSString conversion
int i = 123;
char *buffer;
asprintf(&buffer, "%d", i);
NSString *s = [NSString stringWithUTF8String:buffer];
free(buffer);
@edwardean
edwardean / git_version.sh
Created January 4, 2017 06:37 — forked from trawor/git_version.sh
每次编译把Git的提交次数作为小版本号
#Git 版本数
VERSION_NUMBER=`git rev-list head | sort | wc -l | awk '{print $1}'`
#VERSION_HASH=`git rev-list head | head -1`
echo $VERSION_NUMBER
#echo $VERSION_HASH
##加入版本号
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
@edwardean
edwardean / iOSMapKitFitAnnotations.m
Created December 15, 2016 05:32 — forked from andrewgleave/iOSMapKitFitAnnotations.m
Zooms out a MKMapView to enclose all its annotations (inc. current location)
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapView.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}
@edwardean
edwardean / gist:8d3cb9f852879c6413a1e095fefe437b
Created October 14, 2016 09:59 — forked from n00neimp0rtant/gist:27829d87118d984232a4
UIVisualEffectView blur radius manipulation (new for iOS 9)
// iOS 9 allows you to animate between visual effects, which gives you the
// ability to manipulate the blur radius. this can be useful for animating
// a backdrop for a custom modal, and with a few tricks, can even be set
// indirectly, allowing you to "scrub" between them back and forth with
// a gesture, just like when you pull down Spotlight.
// these are the two effects you want to transition between
UIVisualEffect *startEffect = nil; // "nil" means no blur/tint/vibrancy (plain, fully-transparent view)
UIVisualEffect *endEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
@edwardean
edwardean / SpinlockTestTests.swift
Created October 4, 2016 01:47 — forked from steipete/SpinlockTestTests.swift
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@edwardean
edwardean / DynamicCollectionView.m
Created September 8, 2016 12:08 — forked from frijole/DynamicCollectionView.m
Resize a collection view to its content with AutoLayout via http://stackoverflow.com/a/26232188
@interface DynamicCollectionView : UICollectionView
@end
@implementation DynamicCollectionView
- (void) layoutSubviews
{
[super layoutSubviews];
@edwardean
edwardean / FBAnimationPerformanceTracker.h
Created September 8, 2016 08:58 — forked from zekunyan/FBAnimationPerformanceTracker.h
FBAnimationPerformanceTracker
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@edwardean
edwardean / UIScrollView+ContentOffset.m
Created September 3, 2016 14:22 — forked from mojtabacazi/UIScrollView+ContentOffset.m
Changing UIScrollView contentOffset without triggering scrollViewDidScroll:
CGPoint desiredContentOffset = <#content offset#>;
CGRect scrollBounds = scrollView.bounds;
scrollBounds.origin = desiredContentOffset;
scrollView.bounds = scrollBounds;
@edwardean
edwardean / gist:2cb6f4315b6cf9bb82e24f641b7b1449
Created September 3, 2016 14:19 — forked from jordanekay/gist:8855193
Debug -[UIScrollView setContentOffset:animated:] by changing duration
NSTimeInterval duration = 3.0;
SEL selector = @selector(_setContentOffsetAnimationDuration:);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[scrollView methodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:scrollView];
[invocation setArgument:&duration atIndex:2];
[invocation invoke];
[scrollView setContentOffset:contentOffset animated:YES]