Sto utilizzando una trasformazione CATransform3D per applicare un effetto prospettiva pseudo 3D a una vista.Applicazione di un CATransform3D inverso a sottolivelli di un CALayer che è già stato trasformato
Sto usando il giroscopio nell'iPhone 4 per controllare i parametri della trasformazione.
La vista io sono trasformante ha alcune subviews:
Il risultato è qualcosa di simile:
Il mio prossimo compito è quello di evitare che le sia subviews di essere trasformato mentre la vista principale viene trasformata o applicare una trasformazione inversa in modo che le sottoview non vengano modificate.
Il mio obiettivo è di avere ciascuna sottoveste perpendicolare alla superview, dando l'impressione che siano "in piedi".
Il codice che sto utilizzando per la trasformazione:
- (void)update:(NSTimer *)timer
{
roll = [[[_manager deviceMotion] attitude] roll];
pitch = [[[_manager deviceMotion] attitude] pitch];
yaw = [[[_manager deviceMotion] attitude] yaw];
CALayer *layer = [self.view layer];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, -90 * M_PI/180.0f, 0.0f, 0.0f, 1.0f); // make landscape again
rotationAndPerspectiveTransform.m34 = 1.0/-500; // apply the perspective
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, roll, 1.0f, 0.0f, 0.0f);
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, yaw, 0.0f, 0.0f, 1.0f);
[layer setTransform:rotationAndPerspectiveTransform];
}
Ho provato il seguente codice nel tentativo di invertire la trasformazione, applicando una rotazione di 90 gradi prospettiva alla visualizzazione secondaria attorno all'asse Y:
for (UIView *subview in [self.view subviews])
{
CALayer *sublayer = [subview layer];
//CATransform3D inverseTransformation = [sublayer transform];
CATransform3D inverseTransformation = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0/-500; // apply perspective
inverseTransformation = CATransform3DRotate(inverseTransformation, 90 * M_PI/180.0f, 0.0f, 1.0f, 0.0f);
[sublayer setTransform:inverseTransformation];
}
ma tutto ciò che riesce a fare è far scomparire le sottoview. Se provo a utilizzare la trasformazione esistente dal livello con [sublayer transform]
e ad applicare la rotazione 3d su di esso, quindi lo sfarfallio delle sottoview, ma non ruotare.
La mia conoscenza della matematica Matrix non è eccezionale, quindi non so se questo è l'approccio corretto.
Come è possibile rendere le sottoview sedute perpendicolarmente alla vista superata?