This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGFloat)calculateDynamicHeightWithMaxWidth:(CGFloat)maxWidth { | |
self.translatesAutoresizingMaskIntoConstraints = NO; | |
CGFloat viewMaxWidth = maxWidth ? : CGRectGetWidth([UIScreen mainScreen].bounds); | |
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:viewMaxWidth]; | |
[self addConstraint:widthConstraint]; | |
CGSize fittingSize = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; | |
[self removeConstraint:widthConstraint]; | |
return fittingSize.height; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)zd_shake:(CGFloat)range { | |
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"]; | |
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; | |
animation.duration = 0.5; | |
animation.values = @[@(-range), @(range), @(-range/2), @(range/2), @(-range/5), @(range/5), @(0)]; | |
animation.repeatCount = CGFLOAT_MAX; | |
[self.layer addAnimation:animation forKey:@"shake"]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const void *TouchExtendInsetKey = &TouchExtendInsetKey; | |
static void Swizzle(Class c, SEL orig, SEL new) { | |
Method origMethod = class_getInstanceMethod(c, orig); | |
Method newMethod = class_getInstanceMethod(c, new); | |
if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))){ | |
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); | |
} | |
else { | |
method_exchangeImplementations(origMethod, newMethod); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSObject (ZDWeakAssociate) | |
- (void)zd_setWeakAssociateValue:(id)value forKey:(void *)key { | |
__weak id weakValue = value; | |
objc_setAssociatedObject(self, key, ^{ | |
return weakValue; | |
}, OBJC_ASSOCIATION_COPY); | |
} | |
- (id)zd_getWeakAssociateValueForKey:(void *)key { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSTimer (ZDUtility) | |
+ (NSTimer *)zd_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds | |
block:(void (^)(NSTimer *timer))block | |
repeats:(BOOL)repeats; | |
+ (NSTimer *)zd_timerWithTimeInterval:(NSTimeInterval)seconds | |
block:(void (^)(NSTimer *timer))block | |
repeats:(BOOL)repeats; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)dismiss | |
{ | |
[CATransaction begin]; | |
CATransition *transition = [CATransition animation]; | |
transition.type = kCATransitionReveal; | |
transition.subtype = kCATransitionFromTop; | |
transition.duration = 0.25f; | |
transition.fillMode = kCAFillModeForwards; | |
transition.removedOnCompletion = YES; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MARK:- 超出作用域后执行 | |
//defer(swift延迟调用关键字)宏 (http://blog.sunnyxx.com/2014/09/15/objc-attribute-cleanup/ ) | |
/// 出了作用域时执行block,类似于swift中的defer和EXTScope中的onExit | |
/// | |
/// Example: | |
/// zd_defer { | |
/// /// 所谓作用域结束,包括大括号结束、return、goto、break、exception等各种情况 | |
/// NSLog(@"当前作用域结束,马上要出作用域了"); | |
/// }; | |
/// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "ffi.h" | |
NSMutableArray *g_allocations; | |
ffi_cif g_cif; | |
ffi_closure *g_closure; | |
void *g_replacement_invoke; | |
void *g_origin_invoke; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- config path: '~/.config/wezterm/wezterm.lua' | |
local wezterm = require('wezterm') | |
local config = { | |
color_scheme = 'Shades of Purple (base16)', | |
font_size = 18, | |
font = wezterm.font_with_fallback({ | |
{ family = 'FiraCode Nerd Font', weight = 'Medium' }, | |
{ family = 'PingFang', weight = 'Regular' }, |
OlderNewer