@@ -455,5 +455,45 @@ class TransformSpec: QuickSpec {
455455 expect ( rootView. bounds) . to ( equal ( CGRect ( x: 0 , y: 0 , width: 400.0 , height: 400.0 ) ) )
456456 }
457457 }
458+
459+ describe ( " Modifying layer.anchorPoint change the view.center position " ) {
460+ it ( " aView: Default layer.anchorPoint (0.5, 0.5) " ) {
461+ aView. pin. top ( 100 ) . left ( 100 ) . width ( 100 ) . height ( 100 )
462+
463+ expect ( aView. frame) . to ( equal ( CGRect ( x: 100 , y: 100 , width: 100.0 , height: 100.0 ) ) )
464+ expect ( aView. bounds) . to ( equal ( CGRect ( x: 0 , y: 0 , width: 100.0 , height: 100.0 ) ) )
465+ expect ( aView. center) . to ( equal ( CGPoint ( x: 150 , y: 150 ) ) )
466+ }
467+
468+ it ( " aView: With layer.anchorPoint change (0.25, 0.25) " ) {
469+ aView. layer. anchorPoint = CGPoint ( x: 0.25 , y: 0.25 ) // default is 0.5, 0.5 (Center)
470+ aView. pin. top ( 100 ) . left ( 100 ) . width ( 100 ) . height ( 100 )
471+
472+ expect ( aView. frame) . to ( equal ( CGRect ( x: 100 , y: 100 , width: 100.0 , height: 100.0 ) ) )
473+ expect ( aView. bounds) . to ( equal ( CGRect ( x: 0 , y: 0 , width: 100.0 , height: 100.0 ) ) )
474+ expect ( aView. center) . to ( equal ( CGPoint ( x: 125 , y: 125 ) ) )
475+ }
476+
477+ it ( " aView: With layer.anchorPoint change (1, 1) " ) {
478+ aView. layer. anchorPoint = CGPoint ( x: 1 , y: 1 ) // default is 0.5, 0.5 (Center)
479+ aView. pin. top ( 100 ) . left ( 100 ) . width ( 100 ) . height ( 100 )
480+
481+ expect ( aView. frame) . to ( equal ( CGRect ( x: 100 , y: 100 , width: 100.0 , height: 100.0 ) ) )
482+ expect ( aView. bounds) . to ( equal ( CGRect ( x: 0 , y: 0 , width: 100.0 , height: 100.0 ) ) )
483+ expect ( aView. center) . to ( equal ( CGPoint ( x: 200 , y: 200 ) ) )
484+ }
485+
486+ it ( " aView: With layer.anchorPoint change (0, 0) + transform scale 2 " ) {
487+ aView. layer. anchorPoint = CGPoint ( x: 0 , y: 0 ) // default is 0.5, 0.5 (Center)
488+ aView. transform = CGAffineTransform ( scaleX: 2 , y: 2 )
489+
490+ aView. pin. top ( 100 ) . left ( 100 ) . width ( 100 ) . height ( 100 )
491+
492+ expect ( aView. frame) . to ( equal ( CGRect ( x: 100 , y: 100 , width: 200.0 , height: 200.0 ) ) )
493+ expect ( aView. bounds) . to ( equal ( CGRect ( x: 0 , y: 0 , width: 100.0 , height: 100.0 ) ) )
494+ expect ( aView. center) . to ( equal ( CGPoint ( x: 100 , y: 100 ) ) )
495+ }
496+
497+ }
458498 }
459499}
0 commit comments