Last active
August 29, 2015 14:01
-
-
Save wangzz/de7c9d52bb4d7b29107b to your computer and use it in GitHub Desktop.
记录有用的代码片段
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
记录有用的代码片段 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it is a test file. |
不同view继承体系之间区域转换
例如一个视图控制器的view中有一个UITableView,UITableView的某个cell中有个UITextField,想要得到UITextField在view中的位置:
CGRect rect = [self.view convertRect:textField.frame fromView:textField.superview];
//或者
CGRect rect = [textField.superview convertRect:textField.frame toView:self.view];
不同view继承体系之间点转换
- 把一个点从一个坐标系转换到接收者的坐标系
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view
参数
point
一个视图中坐标系上的点
view
一个视图包含了点和他自身坐标系。如果是图是nil,那么这个方法将尝试转换基于窗口的坐标系。否则视图和那个接收者必须属于同一个UIWindow对象。
- 转换一个点从接收者坐标系到给定的视图坐标系
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
参数
point
一个在调用者坐标系中的点
view
一个包含了需要被转换的点的视图。如果视图是nil,那么这个方法将会转换成基于窗口的坐标。否则视图和接收者都要属于同一个UIWindow对象。
返回值
Block 使用方式
How Do I Declare A Block in Objective-C?
- As a local variable:
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
- As a property:
@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
- As a method parameter:
- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;
- As an argument to a method call:
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
- As a typedef:
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
四舍五入保留两位小数