Skip to content

Instantly share code, notes, and snippets.

View victorchee's full-sized avatar
🎯
Focusing

Victor Chee victorchee

🎯
Focusing
View GitHub Profile
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
@victorchee
victorchee / Shake.m
Created August 21, 2017 00:38
Shake like iPhone delete effect.
[UIView animateWithDuration:.1 delay:0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction animations:^{
cell.transform = CGAffineTransformMakeRotation(.02);
} completion:nil];
// 去除所有返回按钮文字
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-100, 0), for:UIBarMetrics.default)
BOOL animating;
BOOL animationPending;
BOOL animationComplete;
- (void)rotateWithOptions:(UIViewAnimationOptions)options {
NSTimeInterval fullRotationInterval = 4.0;
[UIView animateWithDuration:fullRotationInterval/4.0 delay:0 options:options animations:^{
self.musicIconImageView.transform = CGAffineTransformRotate(self.musicIconImageView.transform, M_PI_2);
} completion:^(BOOL finished) {
if (animating) {
@victorchee
victorchee / DSA.m
Created October 20, 2017 02:54
DSA signature in iOS with OpenSSL.
#import <openssl/dsa.h>
#import <openssl/pem.h>
- (NSString *)DASSignatureStringWithPublicKey:(NSString *)publicKey privateKey:(NSString *)privateKey {
const char *message = [self UTF8String];
BIO *publicBIO = BIO_new_mem_buf((void *)[publicKey UTF8String], -1);
DSA *publicDSA = PEM_read_bio_DSA_PUBKEY(publicBIO, NULL, NULL, NULL);
BIO_free_all(publicBIO);
BIO *privateBIO = BIO_new_mem_buf((void *)[privateKey UTF8String], -1);
/// 扩展UIView增加抖动方法
///
/// - Parameters:
/// - direction: 抖动方向(默认是水平方向)
/// - times: 抖动次数(默认6次)
/// - interval: 每次抖动时间(默认0.2秒)
/// - delta: 抖动偏移量(默认4)
/// - completion: 抖动动画结束后的回调
public func shake(direction: ShakeDirection = .horizontal, times: Int = 6, interval: TimeInterval = 0.2, delta: CGFloat = 4, completion: (() -> Void)? = nil) {
//播放动画
@victorchee
victorchee / gradientLayer.m
Created December 1, 2017 09:05
放射渐变
// 放射渐变
CGContextRef context = UIGraphicsGetCurrentContext();
size_t num_locations = 2;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat components[8] = {1,1,1,1, // 中心颜色(r, g, b, alpha)
.2,.2,.2,1 // 边缘颜色};
CGFloat locations[2] = {0,1};
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, components, locations, num_locations);
@victorchee
victorchee / memory.m
Created December 1, 2017 09:13
获取iOS的内存信息
#import <sys/sysctl.h>
#import <mach/mach.h>
+ (double)getAvailableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
@victorchee
victorchee / itmsUpgrade.m
Created December 28, 2017 00:37
Upgrade from itms service.
[[[NSURLSession sharedSession] downloadTaskWithURL:[NSURL URLWithString:@"https://alpha.migufun.com:38081/alpha/manifest.plist"] completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *plist = [[NSDictionary alloc] initWithContentsOfURL:location];
NSString *version = plist[@"items"][0][@"metadata"][@"bundle-version"];
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
if ([version compare:currentVersion options:NSNumericSearch] == NSOrderedDescending) {
// 需要升级
NSURL *url = [NSURL URLWithString:@"itms-services://?action=download-manifest&url=https://alpha.migufun.com:38081/alpha/manifest.plist"];
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:url];
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"shake" withExtension:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(soundURL), &soundID);
AudioServicesPlaySystemSound(soundID);