ios7没有显示UIImageView

时间:2022-05-07 05:44:19

I have an app I was building for iOS 6 that I recently upgraded to iOS 7. I have a UIScrollView with a few Custom UIViews. Within those UIViews, I have a single UIImageView in each. For some reason, when I set the UIImageView.image in iOS 6, it shows up fine, but iOS 7 will not show them. Here's the code:

我有一个为ios6开发的应用,最近升级到ios7。我有一个UIScrollView和一些定制的uiview。在这些uiview中,每个都有一个UIImageView。出于某种原因,当我设置UIImageView时。在ios6中,它显示的很好,但是ios7不会显示它们。这是代码:

int i = 0;

        for (UIImageView *imageView in myImageViewsOutletCollection)
        {
            imageView.image = nil;
            if (imagesArray.count > i)
                imageView.image = [UIImage imageWithData:[imagesArray objectAtIndex:i]];

            if (imageView.image == nil)
                NSLog(@"signature image with index: %i is nil", i);
                    else
                            NSLog(@"It Worked")

            i++;
        }

My app is logging: @"It Worked", so I know the UIImageView.image isn't nil. What could I be doing wrong?

我的应用程序正在登录:@“它工作了”,所以我知道UIImageView。形象不是零。我做错了什么?

EDIT:

编辑:

I tried the UIImageRenderingMode:

我试着UIImageRenderingMode:

UIImage *imageForView = [UIImage imageWithData:[imagesArray objectAtIndex:i]];
imageForView = [imageForView imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

imageView.image = imageForView;

Still didn't work. However, @Max_Power89 said:

仍然没有工作。然而,@Max_Power89说:

as it is written on the apple developer forum : imageWithData bug report

正如在苹果开发者论坛上所写的:imageWithData bug报告

this must be a bug. i hope they fix the problem early.

这一定是一个bug。我希望他们能尽早解决这个问题。

EDIT 2:

编辑2:

I also added this:

我还添加了这个:

NSData *pngData = UIImagePNGRepresentation(imageView.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];

NSError *writeError = nil;
[pngData writeToFile:[docs stringByAppendingFormat:@"/image.png"] options:NSDataWritingAtomic error:&writeError];
if(writeError!=nil)
{
    NSLog(@"%@: Error saving image: %@", [self class], [writeError localizedDescription]);
}

The image was saved in app's directory, so I know for certain that the image isn't nil.

这个图像被保存在app的目录中,所以我确定这个图像不是nil。

4 个解决方案

#1


1  

It's a problem/bug with Auto Layout constraints in iOS 7. If you remove the constraints on the UIView, it works no problem. You can set frames programmatically if you need to.

ios7中的自动布局限制是一个问题。如果您删除UIView上的约束,它就没有问题。如果需要,可以通过编程方式设置框架。

#2


0  

In iOS 7, loading a image by default only load it's alpha Chanel, and tint it with detail tint color. Your image is showing, just that it's the same color with the background.

在ios7中,默认情况下,加载图像时只加载它的alpha Chanel,并使用细节色调。你的图像正在显示,只是它与背景是相同的颜色。

- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode

Set it to:

将其设置为:

UIImageRenderingModeAlwaysOriginal

#3


0  

as it is written on the apple developer forum : imageWithData bug report

正如在苹果开发者论坛上所写的:imageWithData bug报告

this must be a bug. i hope they fix the problem early.

这一定是一个bug。我希望他们能尽早解决这个问题。

#4


0  

Maybe this will be helpful to anyone: I was having the same issue - al least it looked like this. In the end I figured out, that an UIScrollView was hiding some background view layers. The UIScrollView-background was set to "Group Table View Background Color" in the .xib-File. If I changed that to "clear color" the behavior went back to normal (like in iOS 6). Seems, that the "default behavior" changed for that element from iOS6 to 7. Maybe someone is able to confirm this.

也许这对任何人都有帮助:我也有同样的问题——至少看起来是这样的。最后我发现UIScrollView隐藏了一些后台视图层。UIScrollView-background设置为.xib文件中的“组表视图背景颜色”。如果我将其更改为“清除颜色”,行为就会恢复正常(如iOS6)。也许有人能证实这一点。

#1


1  

It's a problem/bug with Auto Layout constraints in iOS 7. If you remove the constraints on the UIView, it works no problem. You can set frames programmatically if you need to.

ios7中的自动布局限制是一个问题。如果您删除UIView上的约束,它就没有问题。如果需要,可以通过编程方式设置框架。

#2


0  

In iOS 7, loading a image by default only load it's alpha Chanel, and tint it with detail tint color. Your image is showing, just that it's the same color with the background.

在ios7中,默认情况下,加载图像时只加载它的alpha Chanel,并使用细节色调。你的图像正在显示,只是它与背景是相同的颜色。

- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode

Set it to:

将其设置为:

UIImageRenderingModeAlwaysOriginal

#3


0  

as it is written on the apple developer forum : imageWithData bug report

正如在苹果开发者论坛上所写的:imageWithData bug报告

this must be a bug. i hope they fix the problem early.

这一定是一个bug。我希望他们能尽早解决这个问题。

#4


0  

Maybe this will be helpful to anyone: I was having the same issue - al least it looked like this. In the end I figured out, that an UIScrollView was hiding some background view layers. The UIScrollView-background was set to "Group Table View Background Color" in the .xib-File. If I changed that to "clear color" the behavior went back to normal (like in iOS 6). Seems, that the "default behavior" changed for that element from iOS6 to 7. Maybe someone is able to confirm this.

也许这对任何人都有帮助:我也有同样的问题——至少看起来是这样的。最后我发现UIScrollView隐藏了一些后台视图层。UIScrollView-background设置为.xib文件中的“组表视图背景颜色”。如果我将其更改为“清除颜色”,行为就会恢复正常(如iOS6)。也许有人能证实这一点。