Block in iOS (1)
来源:互联网 发布:淘宝闲鱼能小二介入 编辑:程序博客网 时间:2024/05/21 10:29
return_type (^block_name)(param_type, param_type, ...)
^(int number1, int number2){ return number1 + number2 };
如果将block的定义和声明放到一起,就得到下面的一个语句:
int (^add)(int,int) = ^(int number1, int number2){
return number1+number2;
};
我们可以这样使用block:
int resultFromBlock = add(2,2);
[UIView animateWithDuration:0.5
animations:^ {
[customerImageView setAlpha:1.0f];
[customerImageView setCenter:CGPointMake(100,100)];
}
completion:^(BOOL finished) {
[customerImageView removeFromSuperview];
}];
block那么难理解和读,为什么还要用它,使用block有什么好处呢?如下几点希望能够帮组大家理解:
1. 如果大家不使用block来实现几个动画一起的话,就会发现代码显得很繁琐,而且可能需要再单独写一个回调函数,但是使用了block,就完全避免使用beginAnimations/commitAnimations;
2. 代码简单了,不用在几个地方维护开启动画和回调的代码;
3. 貌似苹果推荐我们这样用block。
- Block in iOS (1)
- Block in iOS (2)
- iOS Block详解1
- iOS中Block(1)
- 浅谈ios block(1)
- IOS 代码块block :capturing self strongly in this block is 告警
- ios block
- IOS BLOCK
- ios block
- ios block
- ios block
- IOS BLOCK
- ios block
- iOS Block
- ios block
- IOS block
- iOS Block
- IOS block
- 谈Win32汇编
- Liunx 命令行与shell脚本编程大全 第五章学习笔记(Vim 编辑器使用详解 解释+图示)
- 大数据设计的主要技术
- MONGODB 集群 配置及 客户端PHP 连接
- Xtrabackup备份恢复常用命令与压缩测试
- Block in iOS (1)
- Accepting Un-Trusted Certificates Using The IOS Simulator
- ACM 模板 c++ STL 队列 queue 优先队列
- Advertising Identifier审核被拒终极解决方法
- java实现字符串转化为整数
- 可变参数函数定义要点
- eclipse构建Maven项目 (step-by-step)
- 安装Oracle EM 11g Fusion Middleware Control
- Android 读取文件头判断文件类型