IOS 14 Images not showing in react native - ios

I am unable to render Images on IOS 14 Simulator and Iphone
using Image from react-native and react-native-fast-image

It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix.
react-native/Libraries/Image/RCTUIImageViewAnimated.m
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
} else {
[super displayLayer:layer];
}

Related

What is the code when I want to show a #2x image in app

Today when I search some information about #1x #2x #3x
something confuses me
are these only used as app icon? Because most messages always give me the example of the icon.
and If it can be used in app view, how is the code?
like this?
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.png"]];
Then, iOS will change #1x and #2x itself? OR I need to code like this:
#define deviceIsIPhone5 ([UIScreen mainScreen].applicationFrame.size.height == 568 ? YES : NO)
if (deviceIsIPhone5)
{
self.backgroundImage.image = [UIImage imageNamed:#"background#2x.png"];
}
else
{
self.backgroundImage.image = [UIImage imageNamed:#"background.png"];
}
You don't have to think about #2x #3x.iOS automatically handles it.
All you need to care about is to put right size image into the right box(.xcassets) if you want to show image properly in all iOS devices.
no need to care about 2x,3x and png.
just enter image name only. ios will automatically check image to use according to screen dimensions.
self.backgroundImage.image = [UIImage imageNamed:#"background"];

CGImageDestinationFinalize or UIImageJPEGRepresentation - Crash when saving a large file on IOS 10

I am trying to create tiles for a larger image, and it seems that as of IOS 10 the following code no longer works and crashes with EXC_BAD_ACCESS.
This happens on IOS 10 Device only, IOS 9 works fine.
The crash happens with any image that is larger than ~1300x1300.
Profiling in instruments doesn't yield anything interesting and points to CGImageDestinationFinalize.
There is no memory spike.
I tried both ways below:
UIImage* tempImage = [UIImage imageWithCGImage:tileImage];
NSData* imageData = UIImageJPEGRepresentation(tempImage, 0.8f); // CRASH HERE.
OR
+ (BOOL) CGImageWriteToFile: (CGImageRef) image andPath: (NSString *)path
{
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
if (!destination) {
NSLog(#"Failed to create CGImageDestination for %#", path);
return NO;
}
CGImageDestinationAddImage(destination, image, nil);
if (!CGImageDestinationFinalize(destination)) { // CRASH HERE
NSLog(#"Failed to write image to %#", path);
CFRelease(destination);
return NO;
}
CFRelease(destination);
As I understand it UIImageJPEGRepresentation in turn calls CGImageDestinationFinalize eventually.
Edit: Forgot to mention the images are written to hdd, but about half way through.
This really does seem like something to do with IOS 10, could this be a bug?
I also filed the bug with apple just in case.
Any help or workarounds on how to write out large images is greatly appreciated.
I am going to answer my own question here.
What I have gathered is that IOS 10 has trouble saving a file that has color mode "grayscale".
So if you do
UIImageJPEGRepresentation(tempImage, 0.8f)
and if tempImage is grayscale you will get a crash.
I was processing many images and it didn't click until later that it could be related to the color mode of the image.
I already filed a bug with apple to see what they say, but meanwhile I had to find a temporary fix.
My fix was to convert image to RGB by drawing it and capturing it into a new image.
Sample method:
+ (UIImage *)convertImage:(UIImage *)sourceImage
{
UIGraphicsBeginImageContext(sourceImage.size);
[sourceImage drawInRect:CGRectMake( 0, 0, sourceImage.size.width, sourceImage.size.height)];
UIImage *targetImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return targetImage;
}
Hopefully this helps someone.
tempimage is one of the parameters you passed to UIImageJPEGRepresentation; if it points to a dead object, then that will cause a crash when UIImageJPEGRepresentation tries to use that dead object. check whether tempImage is nil.
check whether you are adding image after calling CGImageDestinationFinalize at destination

iOS9 and initWithPattern with iPad Pro causing repeating background

I now upgraded to iPad Pro simulator for iOS9 and now I am getting a repeating background. Is there something new I must do in order to get the image to correctly expand on iPad Pro. My image sizes dont have a new launch image so I am lost on this.
- (void)addBackgroundImage:(NSString*)imageName {
UIColor *image = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:imageName]];
self.view.backgroundColor = image;
}
Try to use the CGImage in background to avoid repeating background.
Objective-C
self.view.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:#"backgroundImageAsset"].CGImage);
Swift
self.view.layer.contents = UIImage(named:"backgroundImageAsset").CGImage

iOS8 scale glitch when calling drawViewHierarchyInRect afterScreenUpdates:YES

I was converting a project from iOS7 to iOS8 which uses custom transitions and needs to capture the modal after it finishes loading afterScreenUpdates:YES and was seeing that the entire screen scale up for a second and scale back down. I also see this happening in the Flickr app for iOS between sections and on Yelp app when transitioning to a photo on iOS8.
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 22.0);
[self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:YES];
UIGraphicsEndImageContext();
Adding a larger scale factor helps emphasize the glitch more... but i'm just calling this on a button press in the example.
EDIT This appears to happen on iPhone 6 and 6 plus not on the 5.
Sample project github
Do you NEED it to draw after the screen updates? because I'm using:
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
and it seems to work fine on iOS7 and iOS8. I imagine this isn't a great solution for capturing images regularly (like multiple times a second) but it seems to work for a once off blur.
You have to provide #3x launch images for the 6 and 6 plus. The 6 being scaled at 750x1334, and the 6 plus image being scaled at 1242x2208.
Even it looks like bug in API, you can call drawViewHierarchyInRect with afterScreenUpdates set to NO to build snapshot AFTER screen updates if you use cunstruction like this:
typedef void (^CompletionHandlerWithId)(id result);
-(void)imageContaining:(CGRect)rect afterScreenUpdates:(bool)afterScreenUpdates opaque:(BOOL)opaque completion:(CompletionHandlerWithId)completion
{
bool success __block;
UIImage *snapshotImage __block = nil;
CompletionHandler block = ^{
// Create the image
UIGraphicsBeginImageContextWithOptions(self.bounds.size, opaque, [[UIScreen mainScreen] scale]);
success = [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO];
if (success)
{
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect(
[snapshotImage CGImage],
CGRectMake(
snapshotImage.scale*rect.origin.x,
snapshotImage.scale*rect.origin.y,
snapshotImage.scale*rect.size.width,
snapshotImage.scale*rect.size.height));
// or use the UIImage wherever you like
snapshotImage = [UIImage imageWithCGImage:imageRef scale:snapshotImage.scale orientation:UIImageOrientationUp];
CGImageRelease(imageRef);
}
UIGraphicsEndImageContext();
if (completion)
{
if (! success)
{
NSLog(#"Error: [UIView drawViewHierarchyInRect] failed on %#", self);
(completion)(nil);
}
else
{
NSLog(#"Success: [UIView drawViewHierarchyInRect] on %#", self);
(completion)(snapshotImage);
}
}
};
if (afterScreenUpdates)
[CATransaction setCompletionBlock:^{
(block)();
}];
else
(block)();
}
This bug also exists when you run on an iPad2 running iOS7.
Fix: set afterScreenUpdates: to NO
My app has some moving UIButtons, so I don't allow the blur transition until after the movement has stopped. As far as I have found so far, there is no difference in YES or NO.
Appears to be fixed in iOS9 / XCODE 7 builds
I found a solution for me to solve this problem.
I add #3x launch images to my project. And choose launch Screen file to "Main".
This will make app run at original resolution, smaller bounds when run at iphone6, but not glitch when calling drawViewHierarchyInRect. Like this.
Then, scale my view to fullscreen when viewDidLoad.
- (void)viewDidLoad{
[super viewDidLoad];
UIScreen *mainScreen = [UIScreen mainScreen];
CGRect tempFrame=mainScreen.bounds;
double aspect=tempFrame.size.width/320;
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, aspect, aspect);
}
Hope helpful :)

Trouble using UIImageView to show animations

I am an iOS beginner working through the Pragmatic iOS book, and am having trouble with one of the chapter end "challenges" where I am to show slideshow of images in the UIImageView in my nib file.
I have a model class Recipe.h, as well as a ViewController and the standard AppDelegate.h files. Everything that is all wired up correctly, and if I were to show only one image in my UIImageView via self.imageView.image = self.recipe.image, everything works correctly. However, if I were to do the following and attempt to show using animnationImages, no images show up:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//...some code here
if(self.recipe.imageArray){
self.imageView.animationDuration = 2;
self.imageView.animationRepeatCount = 2;
self.imageView.animationImages = self.recipe.imageArray;
NSLog(#"%#", self.imageView.animationImages);
}
}
My NSLog outputs the UIImage: 0x7520d60, UIImage: 0x7522390, which I take it that self.imageView.animationImages has the images located in memory. However, why are the pictures not showing up?
Thanks.
Use
[self.view startAnimating];

Resources