1
我需要以下代码的一些帮助。我现在已经设置了这样一个图像,使图像从黑色变成白色,然后在每次点击时从白色变回黑色。问题在于它不仅仅是翻转颜色,它实际上也是颠倒了图像。我如何让它停止垂直翻转图像?有在那里没有方位元素,所以我一直搞不清楚什么部分是使它做到这一点:iOS从翻转图像停止?
#define FLIP_BUTTON_TAG 200
#define FLIP_VUTTON_TAG2 300
- (void)viewDidLoad
{
[super viewDidLoad];
flipBtn.tag = FLIP_BUTTON_TAG;
}
UIImage* flippedImage;
if(flipBtn.tag==FLIP_BUTTON_TAG)
{
// set the fill color
UIImage *sourceImage1 = self.outletImageView.image;
CGRect rect = CGRectMake(0, 0, sourceImage1.size.width, sourceImage1.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, sourceImage1.CGImage);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextFillRect(context, rect);
sourceImage1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
flippedImage = sourceImage1;
flipBtn.tag = FLIP_VUTTON_TAG2;
}else{
UIImage* sourceImage1 = self.outletImageView.image;
CGRect rect = CGRectMake(0, 0, sourceImage1.size.width, sourceImage1.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, sourceImage1.CGImage);
CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextFillRect(context, rect);
sourceImage1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
flippedImage = sourceImage1;
flipBtn.tag = FLIP_BUTTON_TAG;
}
NSInteger index1 = [imgViewArray indexOfObject:self.outletImageView];
[imgViewArray removeObject:self.outletImageView];
self.outletImageView.image = flippedImage;
[imgViewArray insertObject:self.outletImageView atIndex:index1];
}
这样做!非常感谢! – dfox