63_iOS干货35_修改结构体的值+坐标变换+手势传递参数+view上显示图片

一,修改结构体的某一项值

//修改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

三,手势传递参数

  1. 类似于button传递事件为button本身,手势传递的是gesture,gesture.view可以获取相应的view;
  2. 一个手势只能给一个view,不能两个view公用一个gesture
  3. 手势传递多个变量(本身的gesture.view获取不到)的方法:3种
    1. 利用view的分类,block获取事件,添加手势的地方,和使用参数的地方,可以写在一个方法里(推荐)
  4.   [largeImageView GJSHandleClick:^(UIView *view) {
            [weakSelf dismissEnlargeImage:view andRect:laterRect];
        }];
    1. 利用一个全局的临时变量保存参数,传递前赋值;
    2. 重写一个手势的分类,添加一个参数的属性info;

四,让一个UIView显示图片image的方法

  1. 一个UIImageview在UIView
  2. 通过图片来生成UIColor来设置UIView的背景色
    1. //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]
      
      

       

  3. quarCore方式(推荐)
    1. 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;
      
      

       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值