come ruotare CALayer in un punto selezionato.come ruotare CALayer in un punto
risposta
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, rotationAngle, 0.0, 0.0, -1.0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);
Dove center
è il centro del vostro livello, rotationAngle
è in radianti (positivo è in senso antiorario), e rotationPoint
è la punto su cui si desidera ruotare. center
e rotationPoint
si trovano nello spazio delle coordinate della vista contenente.
Controllare la documentazione CA here.
Si desidera impostare la trasformazione a un CATransform3DRotate, ad esempio:
CATransform3D current = myLayer.transform;
myLayer.transform = CATransform3DRotate(current, DEGREES_TO_RADIANS(20), 0, 1.0, 0);
Questo sarà sufficiente solo per ruotare lo strato attorno al suo centro corrente, non un arbitrario punto. – warrenm
- Definire il sottolivello che si desidera ruotare;
- Impostare il suo
bounds
,position
in superlayer eanchorPoint
.anchorPoint
ha le coordinate relative e punta a unanchorPoint
. Il sottostrato ruoterà attorno a questoanchorPoint
; - Aggiungi trasformazione.
Ad esempio, per ruotare un substrato sul suo punto superview centrale superiore intorno al centro inferiore del substrato, di questo codice:
// 1
let rect = CGRect(x: 0,
y: 0,
width: 20,
height: 20)
let path = UIBezierPath(rect: rect)
let sublayer = CAShapeLayer()
sublayer.fillColor = UIColor.green.cgColor
sublayer.path = path.cgPath
superlayer.addSublayer(sublayer)
// 2
sublayer.bounds = rect
sublayer.position = CGPoint(x: superlayer.bounds.size.width/2, y: 0)
sublayer.anchorPoint = CGPoint(x: 0.5, y: 1)
// 3
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.toValue = 2*CGFloat.pi
rotationAnimation.duration = 3
rotationAnimation.fillMode = kCAFillModeForwards
rotationAnimation.isRemovedOnCompletion = false
sublayer.add(rotationAnimation, forKey: nil)
- 1. come ruotare attorno a un punto specificato in fabric.js?
- 2. Come ruotare un attore dell'immagine in libgdx dal punto centrale?
- 3. Come ruotare UIView, UIImageView o CALayer animati 360˚?
- 4. Come ruotare l'oggetto attorno a un punto usando i quaternioni?
- 5. Masking un CALayer con un altro CALayer
- 6. Come posso lanciare un CALayer con CATransform3D?
- 7. Ruota un punto in un altro punto in 2D
- 8. Come ruotare un livello in un punto di ancoraggio specifico senza saltare?
- 9. Come ruotare un'icona di Android sul suo punto centrale?
- 10. Three.js - Come ruotare un oggetto per guardare Un punto e orientare verso un altro
- 11. Come ruotare un oggetto specifico in openGL?
- 12. Come ruotare un dataframe in Panda?
- 13. Come ruotare un UIImageView in Interface Builder?
- 14. Come ruotare un CannonJS RigidBody?
- 15. three.js - come faccio a ruotare un cilindro attorno a un punto specifico?
- 16. Come ruotare un oggetto avanti e indietro attorno a un punto specifico?
- 17. Ruota il punto su un altro punto in gradi python
- 18. Android, Come posso ruotare una freccia (immagine) attorno a un punto fisso?
- 19. Ruotare un animazione Imagewith
- 20. aggiungi UIImage in CALayer
- 21. Come ruoto un CALayer attorno a una linea diagonale?
- 22. IOS: ruotare un UIImageView
- 23. Come affiancare il contenuto di un CALayer?
- 24. Come ottengo una matrice in cui tradurre, quindi ruotare, quindi tradurre poi ruotare una seconda volta?
- 25. Come ruotare MapView?
- 26. Come ruotare UITableViewCellAccessoryDisclosureIndicator?
- 27. Come ruotare un video con OpenCV
- 28. Actionscript: come ruotare un campo di testo?
- 29. OpenCV: come ruotare IplImage?
- 30. Come ruotare un div utilizzando jQuery
Grazie warrenm suo lavoro ....... –
Hai salvato i miei giorni! Grazie!! –