这可能是一个愚蠢的问题,但是为什么当我执行隐藏按钮时,屏幕截图会发生在隐藏按钮之前?是否有办法确保按钮在屏幕截图发生前就消失了?我需要单独的线程调用吗?谢谢!
if([node.name isEqualToString:@"ScreenshotButton"])
{
[self UserHideAllButtons]; //This hides all menus and buttons
[self captureFullScreen]; This takes a screenshot and sends it to camera
roll
}
-(void)UserHideAllButtons
{
[self showItem:-1 withItemNamed:btnCandy];
[self showItem:-1 withItemNamed:btnCharacter];
[self showItem:-1 withItemNamed:btnDecor];
[self showItem:-1 withItemNamed:btnGifts];
[self showItem:-1 withItemNamed:btnGreeting];
[self showItem:-1 withItemNamed:btnCandyPressed];
[self showItem:-1 withItemNamed:btnCharacter];
[self showItem:-1 withItemNamed:btnDecorPressed];
[self showItem:-1 withItemNamed:btnGiftsPressed];
[self showItem:-1 withItemNamed:btnGreetingPressed];
[self hideObjects:-1 withArrayNamed:candyObjects];
[self hideObjects:-1 withArrayNamed:characterObjects];
[self hideObjects:-1 withArrayNamed:decorObjects];
[self hideObjects:-1 withArrayNamed:giftsObjects];
[self hideObjects:-1 withArrayNamed:greetingObjects];
[self clearMenu];
sliderArrowBtn.zPosition=-1;
sliderMenu.zPosition=-1;
slider.zPosition=-1;
selectedItemBack.zPosition=-1;
}
-(UIImage *)captureFullScreen
{
AppDelegate *_appDelegate = (AppDelegate *)[UIApplicationsharedApplication].delegate;
// if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
// for retina-display
UIGraphicsBeginImageContextWithOptions(_appDelegate.window.bounds.size, NO, [UIScreen
mainScreen].scale);
[_appDelegate.window drawViewHierarchyInRect:_appDelegate.window.bounds
afterScreenUpdates:NO];
screenshot= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Photo Saved To Camera Roll"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
screenshot=[self centerCropImage:screenshot];
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil); //if you need to save
[alert show];
return screenshot;
}发布于 2014-12-13 10:15:42
最可能的原因是,在更新同一帧时,您会同时隐藏和截图。因此,您实际采取的屏幕截图是当前显示的框架的屏幕内容,它不会显示类似隐藏按钮的任何更改,直到Sprite Kit在更新/操作/物理循环结束时重新呈现屏幕。
您将不得不等待一个框架,以便雪碧套件呈现的场景与按钮删除,然后你可以再次显示按钮。请注意,这将不可避免地导致按钮闪烁。
要等待一个框架,只需运行runBlock操作就足够了:
[self runAction:[SKAction runBlock:^{
UIImage* screenshot = [self captureFullScreen];
}];如果不够,请在didEvaluateActions或didSimulatePhysics中运行该操作,以确保该操作计划运行下一个框架。
https://stackoverflow.com/questions/27456627
复制相似问题