Pregunta

Cuando intento tomar una captura de pantalla en spritekit.Probé todos los métodos que pude encontrar en línea.No están funcionando.

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *gameOverScreenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

simplemente no funciona

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

No puedo reconocer mis límites y mi escala.

¿Fue útil?

Solución

No estoy seguro si -drawViewHierarchyInRect:afterScreenUpdates: se supone que funciona con SKView (supongo que sí), pero la razón por la que el segundo ejemplo no se compila es que (1) estás intentando llamarlo y bounds en self (presumiblemente un UIViewController) en lugar de self.view y (2) no ha definido el valor de scale.Simplemente cambie esas dos líneas:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];

Además, el segundo parámetro a UIGraphicsBeginImageContextWithOptions—“opaco”—no debería ser NO a menos que su vista sea transparente, y establecer “afterScreenUpdates” en SÍ sólo es necesario en algunas circunstancias que probablemente no incluyan esta.Es posible que vea un mejor rendimiento si los cambia.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top