首页 > 代码库 > 图片分离--分成两片

图片分离--分成两片

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3c828c } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c32275 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81 } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421 } p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1d9421 } p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #539aa4 } span.s1 { color: #c32275 } span.s2 { color: #000000 } span.s3 { } span.s4 { color: #6122ae } span.s5 { color: #0435ff } span.s6 { color: #703daa } span.s7 { color: #3d1d81 } span.s8 { color: #c91b13 } span.s9 { font: 18.0px "PingFang SC"; color: #c91b13 } span.s10 { font: 18.0px Menlo; color: #000000 } span.s11 { font: 18.0px Menlo } span.s12 { color: #539aa4 }</style>

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

    }];

}

图片分离--分成两片