首页 > 其他 > 详细

图片分离--分成两片

时间:2017-01-03 09:46:40      阅读:144      评论:0      收藏:0      [点我收藏+]

@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);

    }];

}

图片分离--分成两片

原文:http://www.cnblogs.com/daxueshan/p/6243706.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!