В моем проекте у меня есть файлы изображений, хранящиеся в формате jpeg. Код ниже «работает» в том, что он не сбой, но мои изображения не переворачиваются, когда они должны. Я бросил точку останова, чтобы убедиться, что код запущен - это так, но отображаемые изображения не перевернуты. Я предполагаю, что я пропустил что-то основное, но это не выпрыгивает на меня.Перевертывание UIImage горизонтально в UIImageView
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>
в мой файл реализации. Помимо этого, у меня нет идей: как перевернуть изображение по горизонтали.
UPDATE: Намного проще решение
Вместо того, чтобы листать 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
в ответ ниже.