杂记【自娱自乐】

关闭用户交互

self.view.userInteractionEnabled = NO;
//该设置会默认关闭编辑状态,相当于在禁用用户交互的同时附加了以下语句。
[self.view endEditing:YES];

模态跳转,控制器背景透明效果。

UIViewController *controller = [[UIViewController alloc] init];
//Case One:
//首先要设置模态跳转的目标控制器
[nav setModalPresentationStyle:UIModalPresentationOverCurrentContext];
//然后设置根控制器
rootController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootController presentViewController:controller animated:YES completion:nil];

//Case Two:
//如果需要导航控制器包装
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
//这里设置顶层控制器
[nav setModalPresentationStyle:UIModalPresentationOverCurrentContext];
//然后设置根控制器
rootController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootController presentViewController:nav animated:YES completion:nil];

SVN 报以下错误 【引用来源】

Description : The pristine text with checksum '87a646007bab45d5f943a1bf9e76ee9109a6bdd9' was not found
 Suggestion : The operation could not be completed.
 
Technical Information
=====================

      Error : V4Error
  Exception : ZSVNException

Causal Information
==================

Description : The pristine text with checksum '87a646007bab45d5f943a1bf9e76ee9109a6bdd9' was not found
     Status : 155032
解决办法:
1. 首先确定 .svn 文件夹位置,在你本地的WorkFlow 工作目录的根目录下。
2. 根据上面的提示信息,确定出错文件的sha1 值 87a646007bab45d5f943a1bf9e76ee9109a6bdd9
3. 切换到WorkFlow目录下,执行以下命令

sqlite3 .svn/wc.db
#(例子中为87a646007bab45d5f943a1bf9e76ee9109a6bdd9),注意前面的$sha1$要保留

sqlite> select * from pristine where checksum="$sha1$87a646007bab45d5f943a1bf9e76ee9109a6bdd9";
#执行上面的命令后查询结果为空,那么继续下面的操作
sqlite> select * from nodes where checksum="$sha1$87a646007bab45d5f943a1bf9e76ee9109a6bdd9";
#找到一条记录,那么直接删除,命令如下
sqlite> delete from nodes where checksum="$sha1$87a646007bab45d5f943a1bf9e76ee9109a6bdd9";

最后 svn 执行update 操作,基本就OK了。

@synchronized

//线程同步代码块
@synchronized(obj){
    // 线程独占代码
}

运行时系统执行上诉代码时,实际上是通过创建 mutex 锁实现的。
参数 obj 通常指定为该互斥锁要保护的对象,obj 自己不需要是锁对象。
线程如果要执行该代码块,首先会尝试获得锁,如果能获得锁则可以执行块内代码。块执行结束,会同时释放锁。
使用break 或 return 从块内跳出到块外时也被视为块执行终止,并且在快内发生异常时,运行时系统会捕捉异常并释放块。 

eg:
static id g = ...;
- (void)doSomething:(id)arg {
    static id loc = ...;
    @synchronized(g) {...}                        // a
    @synchronized(loc) {...}                      // b
    @synchronized(self) {...}                     // c
    @synchronized(arg) {...}                      // d
    @synchronized([self localLock]) {...}         // e
}

a. 是指定只能单独存在的对象时的情景。同一个对象在其他地方也作为@synchronized 的参数使用时,所有这些块不能同时执行。
b. 也一样,因为限制了参数的使用范围,互斥对象显然只能是该方法内的块。
c. 是各个实例互斥的例子,一个实例一次只能执行一个线程,同一类别的其他实例则多个线程可以同时存在。
d. 在参数对象可能在多个地方更改的情况下有效,但以同样方式使用该对象的所有场所中都需要按照该方式书写,否则就没有任何意义。
e. 也可以指定类对象、或者消息选择器(隐藏参数的 _cmd )来指定方法,不过一般情况下,为互斥的对象使用专门的锁对象是比较可靠的方法。

*** 同递归锁 NSRecursiveLock 一样,可以递归调用而不会引起死锁。***
@synchronized(obj) {
    @synchronized(obj){
  }
}

UITextView 计算文本行数

NSString *text = textView.text;
UIFont *font = [UIFont fontWithName:DP_FONTNAME size:yourFontSize];
CGRect rect = [text boundingRectWithSize:CGSizeMake(preLayoutWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
NSInteger lines = (NSInteger)(roundf(rect.size.height / font.lineHeight));

系统存储空间访问 @骑着JM的hi

//留作备忘
//问题解决方向:需要通过mach层接口访问
vm_statistics64_data_t vmstat;
    natural_t size = HOST_VM_INFO64_COUNT;
    if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vmstat, &size) == KERN_SUCCESS) {
        return (LXDSystemMemoryUsage){
            .free = vmstat.free_count * PAGE_SIZE / NBYTE_PER_MB,
            .wired = vmstat.wire_count * PAGE_SIZE / NBYTE_PER_MB,
            .active = vmstat.active_count * PAGE_SIZE / NBYTE_PER_MB,
            .inactive = vmstat.inactive_count * PAGE_SIZE / NBYTE_PER_MB,
            .compressed = vmstat.compressor_page_count * PAGE_SIZE / NBYTE_PER_MB,
            .total = [NSProcessInfo processInfo].physicalMemory / NBYTE_PER_MB,
        };
    }

位图操作

#define Mask8(x) ((x) & 0xFF)
#define R(x) ( Mask8(x) )
#define G(x) ( Mask8(x >> 8) )
#define B(x) ( Mask8(x >> 16) )
#define A(x) ( Mask8(x >> 24) )
#define RGBAMake(r, g, b, a) ( Mask8(r) | Mask8(g) << 8 | Mask8(b) << 16 | Mask8(a) << 24 )

- (UIImage *)processUsingPixels:(UIImage *)inputImage {
    /*
     * 把UIImage对象转换为需要的核心图形库调用的CGImage对象,同时 得到图形的宽度和高度。
     *
     * */

    CGImageRef inputCGImage = [inputImage CGImage];
    NSUInteger width = CGImageGetWidth(inputCGImage) * 0.25;
    NSUInteger height = CGImageGetHeight(inputCGImage) * 0.25;

    /*
     * 由于使用过的是32位RGB颜色空间模式,你需要定义一些参数
     * bytesPerPixel(每个像素的大小)
     * bitsPerComponent(每个颜色通道的大小)
     * bytesPerRow(每行多大)
     * 数组存储像素的值
     *
     * */

    NSUInteger bytesPerPixel = 4;//字节
    NSUInteger bytesPerRow = bytesPerPixel * width;//字节
    NSUInteger bitsPerComponent = 8; //像素的每个颜色分量使用的bit数,RGB颜色空间下指定8
    UInt32 *pixels;
    pixels = (UInt32 *) calloc(height * width, sizeof(UInt32));

    /*
     * 创建一个RGB模式的颜色空间CGColorSpace和一个容器CGBitmapContext,将像素指针传递到容器中缓存进行存储。
     *
     * */

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    //***强制解压缩图片的关键代码***
    CGContextRef context = CGBitmapContextCreate(pixels, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    /*
    位图布局信息:
    像素格式的字节顺序、alpha的信息、颜色分量是否为浮点数
    typedef CF_OPTIONS(uint32_t, CGBitmapInfo) {
    kCGBitmapAlphaInfoMask = 0x1F,

    kCGBitmapFloatInfoMask = 0xF00,
    kCGBitmapFloatComponents = (1 << 8),

    kCGBitmapByteOrderMask     = kCGImageByteOrderMask,
    kCGBitmapByteOrderDefault  = (0 << 12),
    kCGBitmapByteOrder16Little = kCGImageByteOrder16Little,
    kCGBitmapByteOrder32Little = kCGImageByteOrder32Little,
    kCGBitmapByteOrder16Big    = kCGImageByteOrder16Big,
    kCGBitmapByteOrder32Big    = kCGImageByteOrder32Big
    } CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
  
  //alpha的信息
  typedef CF_ENUM(uint32_t, CGImageAlphaInfo) {
    kCGImageAlphaNone,               /* For example, RGB. */
    kCGImageAlphaPremultipliedLast,  /* For example, premultiplied RGBA */
    kCGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */
    kCGImageAlphaLast,               /* For example, non-premultiplied RGBA */
    kCGImageAlphaFirst,              /* For example, non-premultiplied ARGB */
    kCGImageAlphaNoneSkipLast,       /* For example, RBGX. */
    kCGImageAlphaNoneSkipFirst,      /* For example, XRGB. */
    kCGImageAlphaOnly                /* No color data, alpha data only */
  };

  //字节顺序
  typedef CF_ENUM(uint32_t, CGImageByteOrderInfo) {
      kCGImageByteOrderMask     = 0x7000,
      kCGImageByteOrder16Little = (1 << 12),
      kCGImageByteOrder32Little = (2 << 12),
      kCGImageByteOrder16Big    = (3 << 12),
      kCGImageByteOrder32Big    = (4 << 12)
  } CG_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);

    */


    /*
     * 把缓存中的图形绘制在显示器上,像素的填充格式有创建context的时候进行制定的
     *
     * */

    CGContextDrawImage(context, CGRectMake(0, 0, width, height), inputCGImage);


    /*
     * 幽魂部分
     *
     * */

    UIImage *ghostImage = [UIImage imageNamed:@"ghost"];
    CGImageRef ghostCGImage = [ghostImage CGImage];

    CGFloat ghostImageAspectRatio = ghostImage.size.width / ghostImage.size.height;
    NSInteger targetGhostWidth = width * 0.25;
    CGSize ghostSize = CGSizeMake(targetGhostWidth, targetGhostWidth / ghostImageAspectRatio);
    CGPoint ghostOrigin = CGPointMake(width * 0.5, height * 0.2);
    //创建ghost图片的缓存图
    NSUInteger  ghostBytesPerRow = bytesPerPixel * ghostSize.width;
    UInt32 * ghostPixels = (UInt32 *) calloc(ghostSize.width * ghostSize.height, sizeof(UInt32));

    CGContextRef  ghostContext = CGBitmapContextCreate(ghostPixels, ghostSize.width, ghostSize.height, bitsPerComponent, ghostBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGContextDrawImage(ghostContext, CGRectMake(0, 0, ghostSize.width, ghostSize.height), ghostCGImage);

    /*
     * 图像合成
     *
     * */

    NSUInteger  offsetPixelCountForInput = ghostOrigin.y * width + ghostOrigin.x;
    for (NSUInteger j = 0; j < ghostSize.height; j++) {
        for (NSUInteger i = 0; i < ghostSize.width; i++) {
            UInt32 *inputPixel = pixels + j * width + i + offsetPixelCountForInput;
            UInt32 inputColor = *inputPixel;

            UInt32 *ghostPixel = ghostPixels + j * (int)ghostSize.width + i;
            UInt32 ghostColor = *ghostPixel;

            //Do some processing here
            CGFloat ghostAlpha = 0.5f * (A(ghostColor)/255.0);
            UInt32 newR = R(inputColor) * (1 - ghostAlpha) + R(ghostColor) * ghostAlpha;
            UInt32 newG = G(inputColor) * (1 - ghostAlpha) + G(ghostColor) * ghostAlpha;
            UInt32 newB = B(inputColor) * (1 - ghostAlpha) + B(ghostColor) * ghostAlpha;

            newR = MAX(0, MIN(255, newR));
            newG = MAX(0, MIN(255, newG));
            newB = MAX(0, MIN(255, newB));

            *inputPixel = RGBAMake(newR, newG, newB, A(inputColor));

        }

    }


    /*
     * 黑白效果
     *
     * */

//    for (NSUInteger k = 0; k < height; k++) {
//        for (NSUInteger m = 0; m < width; m++) {
//            UInt32 *currentPixel = pixels + (k * width) + m;
//            UInt32 color = *currentPixel;
//
//            UInt32 averageColor = (R(color) + G(color) + B(color)) / 3.0;
//            *currentPixel = RGBAMake(averageColor, averageColor, averageColor, A(color));
//        }
//
//    }


    //Create a new UIImage
    CGImageRef newCGImage = CGBitmapContextCreateImage(context);
    UIImage *processedImage = [UIImage imageWithCGImage:newCGImage];

    /*
     * 清除
     * */


    CGColorSpaceRelease(colorSpace);
    CGContextRelease(context);
    CGContextRelease(ghostContext);
    free(pixels);
    free(ghostPixels);


    return processedImage;


    //画布
//    UIGraphicsBeginImageContext(CGSizeMake(width, height));
//
//    NSLog(@"Brightness of image:");
//
//    /*
//     * 定义一个指向第一个像素的指针,并使用2个for循环来遍历像素
//     * */
//
//    UInt32 * currentPixel = pixels;
//
//    for (NSUInteger j = 0; j < height; j++) {
//        for (NSUInteger i = 0; i < width; i++) {
//            /*
//             * 得到当前像素的值赋给currentPixel并把它的亮度值打印出来
//             *
//             * */
//            UInt32 color = *currentPixel;
//            printf("%3.0f ",(R(color)+ G(color)+ B(color))/3.0);
//
//            /*
//             * 增加currentPixel的值,使它指向下一个像素。指针运算(32位)+ 1 表示移动4个字节
//             *
//             * */
//            currentPixel++;
//
//        }
//        printf("\n");
//    }


}

ImageIO 全家福


ImageIO.png

监听runloop状态

CFRunLoopRef runloop = CFRunLoopGetCurrent();
CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler(CFAllocatorGetDefault(), kCFRunLoopAllActivities, YES, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
    switch (activity) {
        case kCFRunLoopEntry:
            NSLog(@"进入runLoop");
            break;
        case kCFRunLoopBeforeTimers:
            NSLog(@"处理timer事件");
            break;
        case kCFRunLoopBeforeSources:
            NSLog(@"处理source事件");
            break;
        case kCFRunLoopBeforeWaiting:
            NSLog(@"进入睡眠");
            break;
        case kCFRunLoopAfterWaiting:
            NSLog(@"被唤醒");
            break;
        case kCFRunLoopExit:
            NSLog(@"退出");
            break;
        default:
            break;
    }
});
CFRunLoopAddObserver(runloop, observer, kCFRunLoopCommonModes);
CFRelease(observer);

Type Coding

v@:

WKWebView 加载不全和闪烁问题

H5页面出现,滑动闪烁以及概率性的显示不全
出现问题时,一个显著的标志就是顶层的UIScrollVIew ---> contentSize:{0, 0}
【最终结果是 前端修改CSS样式予以解决】

UI层级树.png
相关状态.png

iPhone 尺寸大全


size.png

依赖同步解决方法

a. NSOperation 操作队列,依赖API
b. 组队列,任务通知机制。
c. GCD栅栏,任务阻塞机制。
d. 信号量机制
e. 设置标记位 【有时并不那么靠谱】

全站输出流控制

#if defined(DEBUG)
    #define SYLog(format, ...) NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];\
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];\
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];\
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSSZ"]; \
        NSString *str = [dateFormatter stringFromDate:[NSDate date]];\
        printf("%s [%s:(%d)] %s:%s\n",[str UTF8String],[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
    #define NSLog(...)  NSLog(__VA_ARGS__);
#else
    #define SYLog(...)
    #define NSLog(...)
#endif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266

推荐阅读更多精彩内容