Skip to content

Instantly share code, notes, and snippets.

@edwardean
edwardean / DeallocationChecker.swift
Created July 2, 2017 13:22
DeallocationChecker.swift
//
// DeallocationChecker.swift
// DeallocationChecker
//
// Created by Arkadiusz Holko on {TODAY}.
// Copyright © 2017 DeallocationChecker. All rights reserved.
//
import UIKit
extension UIViewController {
- (void)drawGradientWithContext:(CGContextRef)context colors:(NSArray <id> *)colors path:(CGPathRef)path
aplha:(CGFloat)alpha startPointY:(CGFloat)startY {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = {0.0, 1.0};
CGContextSaveGState(context);
CGContextAddPath(context, path);
CGContextClip(context);
@edwardean
edwardean / gist:efb19a076e6e72fc15e86c8cd19f1f6a
Created June 5, 2017 06:17
解决layer的shadowPath动画不能跟随bounds保持动画一致的问题
- (void)layoutSubviews {
[super layoutSubviews];
if (self.shouldAnimateShadowPath) {
CAAnimation *animation = [self.layer animationForKey:@"bounds.size"];
if (animation) {
// 通过CABasicAnimation类来为shadowPath添加动画
CABasicAnimation *shadowPathAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"];
// 根据bounds的动画属性设置shadowPath的动画属性
shadowPathAnimation.timingFunction = animation.timingFunction;
shadowPathAnimation.duration = animation.duration;
@edwardean
edwardean / gist:1325912b3bfda284782fb7cda0d40bcf
Last active December 29, 2018 01:22
Find the first Responder
import UIKit
private weak var currentFirstResponder: AnyObject?
extension UIResponder {
@objc func findFirstResponder() -> AnyObject? {
currentFirstResponder = nil
UIApplication.shared.sendAction(#selector(findFirstResponder(_:)), to: nil, from: self, for: nil)
return currentFirstResponder
}
OBJC_PRINT_REPLACED_METHODS
DYLD_PRINT_STATISTICS
OS_ACTIVITY_MODE
- (void)musicAnimation {
CAReplicatorLayer *r = [[CAReplicatorLayer alloc] init];
r.bounds = (CGRect){0,0,60,60};
r.position = self.view.center;
[self.view.layer addSublayer:r];
CALayer *bar = [[CALayer alloc] init];
bar.bounds = CGRectMake(0, 0, 8, 40);
bar.position = CGPointMake(10, 75);
[UIView transitionWithView:_animatedLabel duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ _animatedLabel.textColor = colorChanged?[UIColor greenColor]:[UIColor blackColor]; } completion:^(BOOL finished) { }];
@edwardean
edwardean / gist:abe4a330e86254f46819f2fefc39e154
Created May 4, 2017 10:04
UINavigationBar UIToolBar remove bottom line:
[self.navigationController.navigationBar setTranslucent:NO];
[navigationBar setBackgroundImage:[UIImage imageNamed:@“NavigaionBarBackground”] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[navigationBar setShadowImage:[UIImage new]];
ToolBar.clipToBounds = YES;
@edwardean
edwardean / gist:7304f5393e19b1deda674d40d4dc89ce
Created May 4, 2017 10:03
UINavigationBar title切换动画:
CATransition *animation = [CATransition animation];
animation.duration = 0.5;
animation.type = kCATransitionFade;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.navigationController.navigationBar.layer addAnimation:animation forKey:@"changeTextTransition"];
self.title = title;
@edwardean
edwardean / gist:9b0e7c9ba0c33ab327c5eada0eacff49
Created April 24, 2017 02:12
excute code and only once in swift:
class Once {
static let run: Void = {
print(“code execute”)
}()
}