Some background: I am just trying to do a simple program using xcode 6 beta 7 in swift to screenshot the iphone after I press a button. It is done in SpiteKit and in the game scene. The background is a random png image and the "hello world" default sample text. I programmatically put a press-able button (the default spaceship image is the button) in gamescene didMoveToView function using the following code:
button.setScale(0.2)
screen.frame = CGRect(origin: CGPointMake(self.size.width/4, self.size.height/1.5), size: button.size)
screen.setImage(playAgainButton, forState: UIControlState.Normal)
screen.addTarget(self, action: "action:", forControlEvents: UIControlEvents.TouchUpInside)
self.view!.addSubview(screen)
This sets my press-able button on the screen where it is linked to a function to take a screenshot using this next code:
func action(sender:UIButton!){
UIGraphicsBeginImageContext(self.view!.bounds.size)
self.view!.layer.renderInContext(UIGraphicsGetCurrentContext())
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
}
So this code does take a screenshot, but when I look in photos, only the press-able button is shown and the rest of the image is white. The image is shown below:
Below, I think the screen shot should look like this as this is what the screen looks like in the simulator (I just used some random images/text as background):
Can someone explain to me why the screenshot program is not also taking a picture of the background and how to fix it?
I've looked online and I have not seen any question that is a solution to my problem. Online I saw some similar problems and tried out their fixes: I imported quartzCore, coreGraphics, and coreImages, but with no fix. Also, I tried using the ViewController and setting a UIbutton on there with a IBaction to screen shot, but still get the same white background image. I've tried different background images with the same result.
I am fairly new to programming so, any help would be appreciated! Thank you in advance!
To learn how to get a white background on iPhone, follow the steps given below. Go to your App Store and have it installed. Open the app, use Magic Wand to remove first the background of photo. Then tap the “Share” icon and tap the “Edit Background” button then “Color” to pick color white.
A really good test to see if this is software or hardware is to take a screen shot of the screen when you see the white spot. If the white spot isn't in the screen shot, that means it's an issue with the LCD screen and it needs to be repaired. To take a screen shot, press and hold the Sleep/Wake button, then immediately press the Home Button.
iPhone Stuck on White Apple Screen and Won't Get Past It? PRO TIP: If the issue of iPhone stuck on Apple logo is originated due to software issues you should try using iOS System Recovery which can diagnose and address the glitches in the operating system. You can download iOS System Recovery by clicking here.
iPhone 6s and older - Press and hold down Volume Down button and Home button until screen turns off and then Apple logo appears. But if iPhone still won't get past white Apple logo screen, then you can: Put iPhone into Recovery and update or restore it Try a third-party tool to fix frozen Apple logo
Have you set the background as pattern-background-color? => Maybe this doesn't work as expected with renderInContext
.
Is the background image rendered in self.view
, either as a subview or in its drawRect:
method? => if not, of course it will not be rendered.
The easiest way to get a screenshot is with the function
UIImage *_UICreateScreenUIImage();
you have to declare it first, because its an undocumented function. I'm not sure if Apple will accept an app that contains a call to this function, but I think it will be okay (I know the review guidelines say you must not use undocumented functions, but I think they will not care in this case.) It's available and working in iOS 5 - iOS 8 (i have tested it. don't care about iOS 4.)
Another thing that should also work is to render the whole screen instead of just one particular view:
UIGraphicsBeginImageContext(self.view!.window!.bounds.size)
self.view!.window!.layer.renderInContext(UIGraphicsGetCurrentContext())
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
(note that I replaced view!
with view!.window!
to get the one and only window instance.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With