Skip to content

Instantly share code, notes, and snippets.

@dvlprliu
dvlprliu / SectionHeader.m
Created February 28, 2017 07:00
Make UITableView's section header not pined at top of each section
typedef NS_ENUM(NSUInteger, SectionHeaderType) {
SectionHeaderTypeHeader,
SectionHeaderTypeFooter
};
/**
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SectionHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:REUSED_HEADER_ID];
protocol Identifiable {
associatedtype Identifier: Equatable
var id: Identifier { get }
}
extension CollectionType where Generator.Element: Identifiable {
func indexOf(element: Self.Generator.Element) -> Self.Index? {
return self.indexOf { $0.id == element.id }
}
- (void)animateFromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint duration:(CGFloat)duration {
NSLog(@"------%s-------",__func__);
CGFloat r = sqrtf(powf(startPoint.x - endPoint.x, 2) + powf(startPoint.y - endPoint.y, 2));
NSLog(@"r = %f",r);
CGFloat SIN = (startPoint.y - endPoint.y) / r;
CGFloat COS = (startPoint.x - endPoint.x) / r;
NSLog(@"-----------------");
@dvlprliu
dvlprliu / shake animation
Last active August 29, 2015 13:57
shake animation
- (void)shakenAView:(UIView *)view {
CGPoint leftPoint = CGPointMake(view.center.x - 3, view.center.y);
CGPoint rightPoint = CGPointMake(view.center.x + 3, view.center.y);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, view.center.x, view.center.y);
CGPathAddLineToPoint(path, NULL, leftPoint.x, leftPoint.y);
CGPathAddLineToPoint(path, NULL, rightPoint.x, rightPoint.y);
CGPathAddLineToPoint(path, NULL, leftPoint.x, rightPoint.y);