ipad - How to track successive CGAffineTransforms so as to arrive at a specific point on screen? -


how execute multiple cgaffinetransform operations (in animation blocks) without keeping track of every operation executed?

the translation operation doesn't take x,y coordinates instead values shift by. unless know translated to, @ "location 2," how know values shift "location 3?"

for example:

a uiview's frame @ (0, 0) - position 1. set transform translate (768, 0) , rotate -90 degrees - position 2. time passes , want move (768, 1024) , rotate -90 degrees - position 3.

how know translate move position 2 position 3?

in context, i'm trying achieve ipad view following:

  • a uiview takes entire screen
  • a uitoolbar takes top edge , on top of uiview
  • when ipad rotates, uiview stays device, toolbar rotate on top edge of screen.

i using cgaffinetransform translate , rotate move toolbar. works great, except when rotate ipad multiple times. first translate/rotate work perfect. following transforms off because don't know correct values shift by.

update:

it looks if take current translation (tx, ty) values in uiview.transform struct , use difference between them , new location, works. however, if view has been rotated, not work. tx , ty values can flipped because of previous rotation. i'm not sure how handle that.

update 2:

doing research, i've found can original, unrotated points tx, ty getting abs value of points , possibly swapping x , y if uiview perpendicular. stuck figuring out how correctly apply next set of transforms in right order. seems no matter how concat them, uiview ends in wrong place. seems complicated , there must easier way.

the answer is, apparently, don't track transforms.

so way rotate toolbar around screen not concatenating rotate , translate transform. instead, create rotate transform , set frame in animation block. further, based on new uiinterfaceorientation, set degrees rotate based on compass values of 0, -90, -180, -270. also, set frame size base on same locations.

so:

cgpoint portrait = cgpointmake(0, 0); cgpoint landscapeleft = cgpointmake(768 - 44, 0); cgpoint landscaperight = cgpointmake(0, 0); cgpoint upsidedown = cgpointmake(0, 1024 - 44);  cgsize portraitsize = cgsizemake(768, 44); cgsize landscapeleftsize = cgsizemake(44, 1024); cgsize landscaperightsize = cgsizemake(44, 1024); cgsize upsidedownsize = cgsizemake(768, 44);  cgfloat rotation; cgrect newlocation; switch(orientation) {     case uideviceorientationportrait:         nslog(@"changing portrait");         newlocation.origin = portrait;         newlocation.size = portraitsize;         rotation = 0.0;         break;      case uideviceorientationlandscaperight:         nslog(@"changing landscape right");         newlocation.origin = landscaperight;         newlocation.size = landscaperightsize;         rotation = -90.0;         break;      case uideviceorientationlandscapeleft:         nslog(@"changing landscape left");         newlocation.origin = landscapeleft;         newlocation.size = landscapeleftsize;         rotation = -270.0;         break;      case uideviceorientationportraitupsidedown:         nslog(@"changing upside down");         newlocation.origin = upsidedown;         newlocation.size = upsidedownsize;         rotation = -180.0;         break;      default:         nslog(@"unknown orientation: %d", orientation);         newlocation.origin = portrait;         newlocation.size = portraitsize;         rotation = 0.0;         break;  }  cgrect frame = newlocation; cgaffinetransform transform = cgaffinetransformmakerotation(degrees_to_radians(rotation));  if(lastorientation) {     [uiview beginanimations:nil context:null];     [uiview setanimationduration:.3];     [uiview setanimationcurve:uiviewanimationcurveeasein];     [uiview setanimationbeginsfromcurrentstate:yes]; }  toolbar.transform = transform; toolbar.frame = frame;  // commit changes if(lastorientation) {     [uiview commitanimations]; }  lastorientation = orientation; 

this works beautifully. however, unexpected problem ui elements ios shows on behalf not oriented correctly. i.e., modal windows , popovers keep same orientation underlying uiview. problem renders whole thing moot.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -