我如何将UIImageView
水平分成两半?我不想要两个单独的图像,但更多的只是声明UiImageView
的两半。我的最终目的是,如果我的“球”击中平台的顶部(上半部分),它会反弹。如果球击中平台的下半部分,它会反弹。
答案 0 :(得分:0)
- (void)split
{
UIImage *image = [UIImage imageNamed:@"cat.jpeg"];
CGImageRef imageRef = image.CGImage;
CGImageRef leftRef = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, image.size.width/2, image.size.height));
UIImage *leftImage = [UIImage imageWithCGImage:leftRef];
CGImageRelease(leftRef);
_imageView1.image = leftImage;
CGImageRef rightRef = CGImageCreateWithImageInRect(imageRef, CGRectMake(image.size.width /2, 0, image.size.width , image.size.height));
UIImage *rightImage = [UIImage imageWithCGImage:rightRef];
CGImageRelease(rightRef);
_imageView2.image = rightImage;
}