xcode 带有 iOS 7 的 UIImageView 没有出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18936637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIImageView with iOS 7 not showing up
提问by Cody Winton
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:
我有一个正在为 iOS 6 构建的应用程序,我最近升级到了 iOS 7。我有一个UIScrollView
带有一些 Custom 的应用程序UIViews
。在那些中UIViews
,我UIImageView
在每个中都有一个。出于某种原因,当我UIImageView.image
在 iOS 6 中设置时,它显示正常,但 iOS 7 不会显示它们。这是代码:
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?
我的应用程序正在记录:@"It Worked"
,所以我知道UIImageView.image
不是nil
。我可能做错了什么?
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
this must be a bug. i hope they fix the problem early.
正如在苹果开发者论坛上所写:imageWithData 错误报告
这一定是一个错误。我希望他们早日解决问题。
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.
图像保存在应用程序的目录中,所以我确定图像不是零。
采纳答案by Cody Winton
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.
这是 iOS 7 中自动布局约束的一个问题/错误。如果您删除 上的约束UIView
,它就没有问题。如果需要,您可以通过编程方式设置框架。
回答by nodepond
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 UIScrollViewwas 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-File 中设置为“ Group Table View Background Color”。如果我将其更改为“清除颜色”,则行为将恢复正常(如在 iOS 6 中)。似乎,该元素的“默认行为”从 iOS6 更改为 7。也许有人能够确认这一点。
回答by Kyle Fang
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.
在 iOS 7 中,默认情况下加载图像仅加载它的 alpha Chanel,并使用细节色调颜色对其进行着色。您的图像正在显示,只是它与背景颜色相同。
- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode
Set it to:
将其设置为:
UIImageRenderingModeAlwaysOriginal
回答by Max_Power89
as it is written on the apple developer forum : imageWithData bug report
正如在苹果开发者论坛上所写:imageWithData 错误报告
this must be a bug. i hope they fix the problem early.
这一定是一个错误。我希望他们早日解决问题。