Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:如何根据当前方向翻转图像?_Ios_Uiimage_Orientation - Fatal编程技术网

iOS:如何根据当前方向翻转图像?

iOS:如何根据当前方向翻转图像?,ios,uiimage,orientation,Ios,Uiimage,Orientation,我试图检查图像的当前方向,并将其翻转到与当前相反的方向 如果我的屏幕上只有一个元素,这段代码就可以工作,但只要我增加数组,就有50/50的机会获得正确的方向 -(IBAction)flipBtn:(id)sender { UIImage* flippedImage; if(flipBtn.tag==FLIP_BUTTON_TAG) { UIImage* sourceImage1 = self.outletImageView.image;

我试图检查图像的当前方向,并将其翻转到与当前相反的方向

如果我的屏幕上只有一个元素,这段代码就可以工作,但只要我增加数组,就有50/50的机会获得正确的方向

-(IBAction)flipBtn:(id)sender
{

    UIImage* flippedImage;
    if(flipBtn.tag==FLIP_BUTTON_TAG)
    {
        UIImage* sourceImage1 = self.outletImageView.image;
        flippedImage = [UIImage imageWithCGImage:sourceImage1.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
        flipBtn.tag = FLIP_VUTTON_TAG2;

    }else{
        UIImage* sourceImage1 = self.outletImageView.image;
        flippedImage = [UIImage imageWithCGImage:sourceImage1.CGImage scale:1.0 orientation: UIImageOrientationUp];
        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];

}

而不是
[imgViewArray removeObject:self.outletImageView]

写入:
[imgViewArray removeObjectAtIndex:index1]

然后,您需要检查
flippedImage.imageOrientation==UIImageOrientationUp
,查看它是否反转,并进行相应的更改

通过访问信息字典
[info objectForKey:@“orientation”]

下面是一个方法,该方法将根据您以前的检查返回新的所需方向(您将通过
flippedImage.imageOrientation
作为参数):


这并没有解决问题,它仍然无法检测当前方向是什么,然后对其进行镜像。这与以前的工作方式完全相同
- (UIImageOrientation)orientation:(int)orientation
{
    UIImageOrientation newOrientation;
    switch (orientation)
    {
        case 1:
            newOrientation = UIImageOrientationUp;
            break;
        case 2:
            newOrientation = UIImageOrientationUpMirrored;
            break;

    }  
    return newOrientation;  
}