1. UITextView

@property(nonatomic,readonly,retain) NSTextStorage *textStorage

是 NSMutableAttributedString 的子类

[self.body.textStorage addAttributes:@{ NSStrokeWidthAttributeName : @-3,

NSStrokeColorAttributeName : [UIColor blackColor]}

range:self.body.selectedRange];

这里的 NSStrokeWidthAttributeName 的 -3 和 3 的区别是:

0表示无描边,正数表示描边,负数表示描边+填充;

假设原文字是(foreground color)蓝色的,用加了正数属性后,就仅有描边,成为空心轮廓的样式

2. View Controller Lifecycle(视图控制器生命周期)

所谓的视图控制器生命周期,其实就是一系列的方法,当事件发生时,会被发送至 UIViewController。如果需要重写这些方法,记得先super,例如:[super viewDidLoad];

解释下super:

向super发送消息时,系统在查找方法时会跳过当前对象的类,从父类开始查询,相当于是先调用了父类的同名方法。

viewDidLoad

- (void)viewDidLoad

适合放置视图控制器的初始化代码,一个生命周期中只会调用一次;

输出口(Outlet)已经设置好,故可以设置各种UI的初始化展示;

有一类操作不适合添加:关于视图几何的代码,因为在 viewDidLoad 被调用时,视图的边界(bounds)还没有定下来,它可能不会出现在预定位置,屏幕可能旋转之类的;总之,关于视图的大小、位置(统称几何)的代码不适合放在 viewDidLoad 中;

viewWillAppear

- (void)viewWillAppear:(BOOL)animated

每次视图重新在屏幕上显示时,viewWillAppear 就会被调用;

此时视图的几何信息已经设置,在这里可以执行一些基于几何的初始化;

viewWillDisappear

- (void)viewWillDisappear:(BOOL)animated

当视图从屏幕离开时,viewWillDisappear会被调用;

可以做些记住当前状态或保存数据的操作,以便重新回到视图时恢复;

viewDidAppear

- (void)viewDidAppear:(BOOL)animated

viewDidDisappear

- (void)viewDidDisappear:(BOOL)animated

viewWillLayoutSubviews

- (void)viewWillLayoutSubviews

当视图的frame变化,子视图重现布局时被调用,比如:屏幕旋转;

viewDidLayoutSubviews

- (void)viewDidLayoutSubviews

Between "will" and "did", autolayout will happen;

didReceiveMemoryWarning

- (void)didReceiveMemoryWarning

系统内存不足时会发送这个消息;

收到这个警告时,需要释放内存,也就是释放堆中的内容,也就是将强指针设为nil;

- (void)setup{ };

- (void)awakeFromNib{

[self setup];

}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

[self setup];

return self;

}

3. NSNotification

The “radio station” from the MVC slides.

radio station 包括了收听(tune into)消息和广播(broadcast)消息两块,本节只介绍收听的;

收听里面又分了收听系统消息和收听自定义的来自模型的消息,本节只介绍收听系统消息;

每一个iOS应用中都有一个 NSNotificationCenter 对象,对象可以将自己注册为某个通知的观察者(observer),例如:“如果有人找到了我丢失的

CS193p Lecture 5 - View Controller Lifecycle的更多相关文章

  1. iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)

    这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...

  2. 报错:Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?

    原因分析:在StoryBoard中没有一个view controller设置了Initial Scene. 解决方案:在Storyboard中,选择一个view conroller作为story bo ...

  3. iOS架构师之路:控制器(View Controller)瘦身设计

    前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...

  4. View Controller Relationships

    Parent-child relationshipsParent-child relationships are formed when using view controller container ...

  5. Model View Controller

    On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defau ...

  6. UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior

    Attempting to load the view of a view controller while it is deallocating is not allowed and may res ...

  7. Application tried to present a nil modal view controller on target “Current View Controller”解决方案

    情景再现 1,自定义一个storyboard: 打开xcode,按下cmd+N,新建一个Storyboard--->next 将新建立的storyboard命名为:TestViewControl ...

  8. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  9. UIStoryboard类介绍(如何从Storyboard中加载View Controller)

    如何从Storyboard中加载View Controller? 1. 首先了解下UIStoryboard类: @class UIViewController; @interface UIStoryb ...

随机推荐

  1. 类的property特性

    目录 什么是 property特性 简单示例 property属性的两种方式 装饰器 类属性方式 property+类的封装 应用 私有属性添加getter和setter方法 使用property升级 ...

  2. 3.Python自我修炼(升仙中....整数,布尔值,字符串,for循环)

    python学习(整数,布尔值,字符串,for循环) 1.整数 ​ 在python3中所有的整数都是int类型. 但在python2中如果数据量比较大. 会使用long类型.但是在python3中不存 ...

  3. 黑马MySQL数据库学习day01 安装多个版本MySQL mysqld.exe工具

  4. day01 继承

  5. IDEA 快捷键MacOS

    Alt + Enter 导入包,自动修正 Command + N 查找类 Command + Shift + N查找文件 Command + Alt + L格式化代码 Command + Alt + ...

  6. java多线程模拟红绿灯案例

    代码Lighter.java: package pack1; /** * 灯线程 * @author Administrator * */ public class Lighter extends T ...

  7. Gym - 101810E ACM International Collegiate Programming Contest (2018)

    bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #def ...

  8. 【转】Effective C#观后感之提高Unity中C#代码质量的21条准则

    转自:http://blog.csdn.net/swj524152416/article/details/75418162 我们知道,在C++领域,作为进阶阅读材料,必看的书是<Effectiv ...

  9. javaoo面向对象

  10. Asp.net开发必备51种代码

    1.//弹出对话框.点击转向指定页面 Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script> ...