在UIImageView

时间:2015-07-17 18:56:41

标签: ios objective-c uiimageview uiimage

在我的项目中,我的图像文件以jpeg格式存储。下面的代码“有效”,因为它不会崩溃,但我的图像在它们应该的时候不会翻转。我输入了一个断点以确保代码正在运行 - 它是,但显示的图像不会被翻转。我猜我错过了一些基本的东西,但它并没有向我跳出来。

if (self.isTimer == YES) {
    // this is where images get dumped if they exist
    NSMutableArray *imageArray = [[NSMutableArray alloc] init];

    for (int imageNumber = 1; self.currentItem.photo != nil; imageNumber++) {
        NSString *fileName = [NSString stringWithFormat:@"%@-%d", self.currentItem.photo, imageNumber];
        if ([UIImage imageNamed:fileName]) {
            UIImage *image = [UIImage imageNamed:fileName];
            // test whether count is even or odd
            if (self.currentItem.sideMultiplier.intValue == 1) {
                // if there's only one side to be done, dump unflipped images in array
                [imageArray addObject:image];
                NSLog(@"regular image added to array");
            } else {
                // if there are 2 sides, determine if it's even or odd side
                if (self.stretchSideMultiplierCount % 2 == 1) {
                    // add a unflipped image to the array
                    [imageArray addObject:image];
                    NSLog(@"regular image added to array");
                } else {
                    // ** I want to add a FLIPPED IMAGE here
                    UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored];
                    [imageArray addObject:flippedImage];
                    NSLog(@"flipped image added to array");
                }
            }
            NSLog(@"%@ added to imageArray", fileName);
        } else {
            break;
        }
    }

我关注这篇文章,但一切都没有发生。

How to flip UIImage horizontally?

我将#import <QuartzCore/QuartzCore.h>添加到我的实施文件中。除此之外,我没有想法:如何水平翻转图像。

更新:更简单的解决方案

我翻了UIImage而不是翻转UIImageView。我之前用于创建imageArray的代码现在看起来像这样:

if (self.isTimer == YES) {
    // this is where images get dumped if they exist
    NSMutableArray *imageArray = [[NSMutableArray alloc] init];

    for (int imageNumber = 1; self.currentItem.photo != nil; imageNumber++) {
        NSString *fileName = [NSString stringWithFormat:@"%@-%d", self.currentItem.photo, imageNumber];
        if ([UIImage imageNamed:fileName]) {
            UIImage *image = [UIImage imageNamed:fileName];
            [imageArray addObject:image];
            NSLog(@"image added to array");
            NSLog(@"%@ added to imageArray", fileName);
        } else {
            break;
        }
    }

我用来翻转UIImageView的代码在下面的答案中。

1 个答案:

答案 0 :(得分:2)

问题解决了。我翻了 UIImage ,而不是翻转UIImageView,如下所示:

self.myImageView.transform = CGAffineTransformMakeScale(-1, 1);