push到一个页面进行绘图时,设置如下:

  1. CALayer * layer = [CALayer layer];
  2. layer.frame = CGRectMake(, , , );
  3. layer.delegate = self;
  4. [layer setNeedsDisplay];
  5. [self.view.layer addSublayer:layer];
  1. -(void) drawLayer: (CALayer*) layer inContext: (CGContextRef) context

设置delegate后,点击返回按钮时会奔溃。没有push直接绘制的时候就没有问题。

设置其delegate为uiview类型实例。会导致程序crash。

关于这一点,苹果官方在文档中已有说明。解决办法:

  1. he lightest-wight solution would be to create a small helper class in the the file as the UIView that's using the CALayer:
  2.  
  3. In MyView.h
  4.  
  5. @interface MyLayerDelegate : NSObject
  6. . . .
  7. @end
  8. In MyView.m
  9.  
  10. @implementation MyLayerDelegate
  11. - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx
  12. {
  13. . . .
  14. }
  15. @end
  16. Just place those at the top of your file, immediately below the #import directives. That way it feels more like using a "private class" to handle the drawing (although it isn't -- the delegate class can be instantiated by any code that imports the header).

没怎么看懂:

直接继承CALayer或者CAShapeLayer重写:

  1. - (void)drawInContext:(CGContextRef)ctx

就可以

关于CALayer导致的crash问题的更多相关文章

  1. 打开Voice Over时,CATextLayer的string对象兼容NSString和NSAttributedString导致的Crash(二解决思路3)

    续前一篇:打开Voice Over时,CATextLayer的string对象兼容NSString和NSAttributedString导致的Crash(二解决思路2)ok,到这里已经能够锁定范围了, ...

  2. 案例:Standby RAC遭遇ORA-1157,1111,1110导致实例crash处理

    案例:Standby RAC遭遇ORA-1157,1111,1110导致实例crash处理 环境:RHEL 6.5 + Oracle RAC 11.2.0.4 + Dataguard 今天在实验环境的 ...

  3. 解决iOS7中UITableView在使用autolayout时layoutSubviews方法导致的crash

    近期公司项目上线后,出现了大量的crash,发生在iOS7系统上,和UITableView相关: Auto Layout still required after executing -layoutS ...

  4. 一些Windows API导致的Crash以及使用问题总结

    RegQueryValueEx gethostbyname/getaddrinfo _localtime64 FindFirstFile/FindNextFile VerQueryValue Crea ...

  5. 打开Voice Over时,CATextLayer的string对象兼容NSString和NSAttributedString导致的Crash(一现象)

    一.现象:iPhone真机打开Voice Over的情况下,iPhone QQ空间工程,Xcode 真机编译启动必Crash,main函数里面 NSSetUncaughtExceptionHandle ...

  6. Latch导致MySQL Crash

    作者:沃趣科技数据库专家 董红禹 问题概述 最近我们遇到一个MySQL的问题,分析后很有代表意义,特地写出来供大家参考.出现问题是,数据库先是被置为只读,然后过了一段时间,MySQL直接Crash掉了 ...

  7. 一些Windows API导致的Crash以及使用问题总结(API的AV失败,可以用try catch捕捉后处理)

    RegQueryValueEx gethostbyname/getaddrinfo _localtime64 FindFirstFile/FindNextFile VerQueryValue Crea ...

  8. 捉虫日记 | MySQL 5.7.20 try_acquire_lock_impl 异常导致mysql crash

    背景 近期线上MySQL 5.7.20集群不定期(多则三周,短则一两天)出现主库mysql crash.触发主从切换问题,堆栈信息如下: 从堆栈信息可以明显看出,在调用 try_acquire_loc ...

  9. systemd之导致内核 crash

    本文主要讲解linux kernel panic系列其中一种情况: Attempted to kill init! exitcode=0x0000000b 背景:linux kernel 的panic ...

随机推荐

  1. Codeforces 208A-Dubstep(字符串)

    Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performanc ...

  2. Idea中快捷键与小技巧的总结-->持续更新

    1.Scala类或单例对象中快速声明实例对象: eg. new SparkContext(conf).var 系统会自动提示,可以自动补全,如图: 2.ctrl+i与ctrl+o的区别: ctrl + ...

  3. TF之RNN:实现利用scope.reuse_variables()告诉TF想重复利用RNN的参数的案例—Jason niu

    import tensorflow as tf # 22 scope (name_scope/variable_scope) from __future__ import print_function ...

  4. 机器学习模型从windows下 spring上传到预发布会导致模型不可加载

    1.通过上传到redis,程序通过redis拉取模型,解决问题. 2.问题原因初步思考为windows下模型文件上传到 linux导致,待继续跟进查找.

  5. 潭州课堂25班:Ph201805201 django 项目 第二十七课 docker简介,配置文件 (课堂笔记)

    新闻搜索功能实现 一.docker介绍 1.什么是docker? 使用容器让创建.部署.运行应用程序更简单的一个工具 让应用所需的库和依赖环境打包 有一点点像虚拟机 2.为什么使用docker? 3. ...

  6. 潭州课堂25班:Ph201805201 django 项目 第十课 自定义错误码,完成图片验证码,用户是否被注册功能 (课堂笔记)

    把 视图传到前台的  JsonResponse(data=data) 先进行处理,之后再传到前台, 处理:引用自定义错误代码,把错误代码返回给前台,前台根据错误代码中文提示 class Code: O ...

  7. [CF536D]Tavas in Kansas

    [CF536D]Tavas in Kansas 题目大意: 一张\(n(n\le2000)\)个点,\(m(m\le10^5)\)条边的无向带权连通图(权值可以为负).A.B两人分别在\(s,t\)点 ...

  8. python系统编程(十一)

    同步应用 多个线程有序执行 from threading import Thread,Lock from time import sleep class Task1(Thread): def run( ...

  9. shell脚本使用--sleep

    #!/bin/bash #filename.sh echo -n Count: tput sc count=; while true; do ]; then let count++; ; tput r ...

  10. 安装并运行Hello World

    新建虚拟环境并安装Flask pip install Flask 运行HelloWorld from flask import Flask #导入Flask类 app = Flask(__name__ ...