2月4学习概况

static的作用

  • 修饰局部变量

    • 让局部变量只初始化一次
    • 局部变量在程序中只有一份内存
    • 并不会改变局部变量的作用域,仅仅是改变了局部变量的生命周期(只到程序结束,这个局部变量才会销毁)
  • 修饰全局变量

    • 全局变量的作用域仅限于当前文件

autoresizingMask

默认情况下,所有控制器view的autoresizingMask属性都包含了UIViewAutoresizingFlexibleWidth和UIViewAutoresizingFlexibleHeight两个值

didMoveToParentViewController

/**
 * 当前控制器已经被添加到某个父控制器上时就会调用这个方法
 */
- (void)didMoveToParentViewController:(UIViewController *)parent{
    [super didMoveToParentViewController:parent];
    NSLog(@"didMoveToParentViewController - %@", parent);
}

两个用处:

  • 监听当前控制器被添加到另外一个父控制器
  • 监听当前控制器从父控制器中移开

注意,如果是自定义的控制器添加到另一个父控制器中,不会主动调用这个方法,需要我们手动调用。具体解释看苹果官方解释
Called after the view controller is added or removed from a container view controller.
Your view controller can override this method when it wants to react to being added to a container.
If you are implementing your own container view controller, it must call the didMoveToParentViewController: method of the child view controller after the transition to the new controller is complete or, if there is no transition, immediately after calling the addChildViewController: method.
The removeFromParentViewController method automatically calls the didMoveToParentViewController: method of the child view controller after it removes the child.

automaticallyAdjustsScrollViewInsets属性

  @property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets

A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.
The default value of this property is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.

实现拷贝的方法

  • copy
    • 只会产生不可变的副本对象(比如NSString)
  • mutableCopy
    • 只会产生可变的副本对象(比如NSMutableString)

拷贝自定义的对象

有两点要求,拷贝的对象

  • 遵守<NSCopying>协议,
  • 实现- (id)copyWithZone:(NSZone *)zone方法

字符串copy和strong的区别

两种方式的set方法不一样

@property (nonatomic, copy) NSString *name;
- (void)setName:(NSString *)name{
    _name = [name copy];
}

@property (nonatomic, strong) NSString *name;
- (void)setName:(NSString *)name{
    _name = name;
}

注意:
@property (nonatomic, copy) NSMutableString *name;
这样写是不合理的:name属性值永远是不可变,所以定义为NSMutableString是不合理的。

copy和mutablecopy的区别

这里写图片描述

scrollViewDidEndScrollingAnimation

/**
 * scrollView结束了滚动动画以后就会调用这个方法(比如- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;方法执行的动画完毕后)
 */
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

scrollViewDidEndDecelerating

/**
 * 手指松开scrollView后,scrollView停止减速完毕就会调用这个
 */
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

UIScrollView内部子控件添加约束的注意点

  • 子控件的尺寸不能通过UIScrollView来计算,可以考虑通过以下方式计算
    • 可以设置固定值(width==100,height==300)
    • 可以相对于UIScrollView以外的其他控件来计算尺寸
  • UIScrollView的frame应该通过子控件以外的其他控件来计算
  • UIScrollView的contentSize通过子控件来计算
    • 根据子控件的尺寸以及子控件与UIScrollView之间的间距

数组与指针的关系

指针p的加减法运算

  • 指针p + N
    • p里面存储的地址值 + N * 指针所指向类型的占用字节数
  • 指针p - N
    • p里面存储的地址值 - N * 指针所指向类型的占用字节数

数组名

  • 存储的是数组首元素的地址
  • 等价于:一个指向数组首元素的指针
  • 数组名 + 1 的跨度:数组首元素的占用字节数

其他结论

  • &num + 1的跨度:num的占用字节数
  • 如果 int str[3] = {1, 2, 3};
    &str代表指向数组str的指针,&str + 1的跨度为12;

计算代码执行的时间

    CFTimeInterval begin = CFAbsoluteTimeGetCurrent();
    .......

    CFTimeInterval end = CFAbsoluteTimeGetCurrent();

    NSLog(@"%f", end - begin);

同步异步 && 串行并发

  • 同步函数 + 串行队列:不会开启新的线程,在当前线程执行任务。任务是串行的,执行完一个任务,再执行下一个任务
  • 异步函数 + 串行队列:会开启一个新的线程,但是任务是串行的,执行完一个任务,再执行下一个任务
  • 同步函数 + 并发队列:不会开启新的线程
  • 异步函数 + 并发队列:可以同时开启多条线程
  • 异步函数 + 主队列:只在主线程中执行任务
  • 同步函数 + 主队列:主队列中添加的同步操作永远不会被执行,会死锁
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值