zoukankan      html  css  js  c++  java
  • 图片分离--分成两片

    @interface ViewController ()

    @property (nonatomic,strong)UIImageView *topImageView;

    @property(nonatomic,strong)UIImageView *bottomImageView;

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100, 300, 100, 30)];

        label.textColor=[UIColor redColor];

        label.textAlignment=NSTextAlignmentCenter;

        label.text=@"你看到我了" ;

        [self.view addSubview:label];

        

        UIImage *imageTop=[UIImage imageNamed:@"1111.jpg"];

        //根据创建的image 进行区域裁剪(关键代码)

        CGImageRef refTopImg=CGImageCreateWithImageInRect(imageTop.CGImage, CGRectMake(0, 0, imageTop.size.width, imageTop.size.height/2));

       _topImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667/2)];

        _topImageView.image=[UIImage imageWithCGImage:refTopImg];

        [self.view addSubview:_topImageView];

        

        CGImageRef refBottomImg=CGImageCreateWithImageInRect(imageTop.CGImage, CGRectMake(0, imageTop.size.height/2, imageTop.size.width, imageTop.size.height/2));

        _bottomImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 667/2, 375, 667/2)];

        _bottomImageView.image=[UIImage imageWithCGImage:refBottomImg];

        

        [self.view addSubview:_bottomImageView];

        

        

        

        

        

    }

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

    {

        [UIView animateWithDuration:1 animations:^{

           

            _topImageView.frame=CGRectMake(0, -667/2, 375, 667/2);

            

            _bottomImageView.frame=CGRectMake(0, 667, 375, 667/2);

        }];

    }

  • 相关阅读:
    Linux/ visual studio 编译使用Poco
    无法安装 golang.org/x/tools/的库
    大牛blog汇总
    Redis整合Spring结合使用缓存实例
    js增加收藏
    iOS学习笔记12-网络(一)NSURLConnection
    Kick the ball!(dfs)湖南省赛第十届
    windows程序设计——飞机大战笔记(Access数据库的使用)
    DataGridView.DataSource= list(Of T)
    面试之SQL(1)--选出选课数量&gt;=2的学号
  • 原文地址:https://www.cnblogs.com/daxueshan/p/6243706.html
Copyright © 2011-2022 走看看