0
我需要做的是從左到右翻轉一個CGImageRef,它是CALayer的一個conntents屬性。我一直在使用Google進行徹底搜索,以找到一種直接翻轉它的方式,但仍然是徒勞。所以我決定做的是翻轉UIImage,然後將它的CGImage屬性設置爲CALayer的內容。不能翻轉CGImage
所以我所做的是:
UIImage *src = [UIImage imageNamed:@"res/images/lizard.png"];
src = [UIImage imageWithCGImage:src.CGImage scale:1.0 orientation:UIImageOrientationRightMirrored];
UIImageView *test = [[UIImageView alloc] initWithImage:src];
[test setFrame:CGRectMake(20, 20, 50, 50)];
[self.view addSubview:test];
[lizard.layer setContents:((id)test.image.CGImage)];
,但它是徒勞的,該層仍然沒有翻轉。我接下來做的是:
UIImage *src = [UIImage imageNamed:@"res/images/lizard.png"];
UIImageView *test = [[UIImageView alloc] initWithImage:src];
[test setFrame:CGRectMake(20, 20, 50, 50)];
[self.view addSubview:test];
test.transform = CGAffineTransformIdentity;
test.transform = CGAffineTransformMakeScale(-1.0, 1.0);
[lizard.layer setContents:((id)test.image.CGImage)];
但不幸的是,它仍然不給我我需要什麼。名稱爲test
的UIImageView按預期顯示 - 將其翻轉,但lizard.layer的內容不是。怎麼會發生? 你能幫我嗎?
1)是否有正常的方法來翻轉CALayer的內容?
2)如果不是那麼我該如何翻轉CGImageRef來正確設置內容?
如何將轉換應用到lizard.layer? – 2012-03-20 09:06:00
你可以使用這個methos-(void)setAffineTransform:(CGAffineTransform)m將轉換分配給CAlayer的; – Vignesh 2012-03-20 09:17:27
它的工作原理,但不是我需要它如何工作。它翻轉圖像,但它翻轉...我不知道如何描述...圖像不只是翻轉,它從頂部和底部消失到中心,然後出現從中心到底部和頂部,真的很難解釋,但它不像我需要的那樣工作。 – 2012-03-20 09:25:09