一,修改结构体的某一项值
//修改frame的x值
CGRect frame = self.view.frame;
frame.origin.x = 10;
self.view.frame = frame;
二,坐标变换
// 1,将像素point从view中转换到当前视图中,返回在当前视图中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
// 用法举例:controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,现在要把UITableViewCell中的某个点Point转换到controllerA的view中
// 在controllerA中实现:
CGRect point = [cell convertPoint:aPoint toView:self.view];
// 此 point 为在 controllerA 的 view 中的 point
//2,将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 用法举例:controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,现在要把UITableViewCell中的某个点Point转换到controllerA的view中
// 在controllerA中实现:
CGRect point = [self.view convertPoint:aPoint fromView:cell];
// 此 point 为在 controllerA 的 view 中的 point
// 3,将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 用法举例:controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,cell上放有一个button,现在要把UITableViewCell中的subview(btn)的frame转换到controllerA的view中
// 在controllerA中实现:
CGRect rect = [self.view convertRect:cell.btn.frame fromView:cell];
// 或当已知btn时:
CGRect rect = [self.view convertRect:btn.frame fromView:btn.superview];
// 此 rect 为 btn 在 controllerA 的 view 中的 rect
// 4,将rect从view中转换到当前视图中,返回在当前视图中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
// 用法举例:controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,cell上放有一个button,现在要把UITableViewCell中的subview(btn)的frame转换到controllerA的view中
// 在controllerA中实现:
CGRect rect = [cell convertRect:cell.btn.frame toView:self.view];
// 或当已知btn时:
CGRect rect = [btn.superview convertRect:btn.frame toView:self.view];
// 此 rect 为 btn 在 controllerA 的 view 中的 rect
三,手势传递参数
- 类似于button传递事件为button本身,手势传递的是gesture,gesture.view可以获取相应的view;
- 一个手势只能给一个view,不能两个view公用一个gesture
- 手势传递多个变量(本身的gesture.view获取不到)的方法:3种
- 利用view的分类,block获取事件,添加手势的地方,和使用参数的地方,可以写在一个方法里(推荐)
-
[largeImageView GJSHandleClick:^(UIView *view) {
[weakSelf dismissEnlargeImage:view andRect:laterRect];
}];
- 利用一个全局的临时变量保存参数,传递前赋值;
- 重写一个手势的分类,添加一个参数的属性info;
四,让一个UIView显示图片image的方法
- 一个UIImageview在UIView
- 通过图片来生成UIColor来设置UIView的背景色
-
//1 . imageName方式:
如果图片较小,并且频繁使用的图片,使用imageName:来加载图片(按钮图片/主页图片/占位图)
self.view.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"home"]];
//2 . contentOfFile方式:
如果图片较大,并且使用次数较少,使用 imageWithContentOfFile:来加载(相册/版本新特性)
NSString *path = [[NSBundle mainBundle]pathForResource:@"name" ofType:@"png"];
self.view.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]
- quarCore方式(推荐)
-
UIImage *image = [UIImage imageNamed:@"3549"];
//推荐这样创建image对象:UIImage *image = [UIImage imageWithContentsOfFile:path];
self.view.layer.contents = (id)image.CGImage;
//背景透明加上这一句
self.view.layer.backgroundColor = [UIColor clearColor].CGColor;