ios - How to create a CATransform3D matching another made using setValue:forKey: -
i tried create catransform3d, got wrong. following code do want, using key-values:
[_transitionlayer setvalue:[nsnumber numberwithfloat:metrics.translationpointsx] forkeypath:@"sublayertransform.translation.x"]; [_transitionlayer setvalue:[nsnumber numberwithfloat:metrics.radians] forkeypath:@"sublayertransform.rotation.y"]; [_transitionlayer setvalue:[nsnumber numberwithfloat:metrics.translationpointsz] forkeypath:@"sublayertransform.translation.z"];
and here's how tried set doing catransform3d:
sublayertransform.m34 = -0.000555; catransform3d sublayertransform = catransform3dmaketranslation(0, 0, 0); sublayertransform = catransform3dtranslate(sublayertransform, metrics.translationpointsx, 0, 0); sublayertransform = catransform3drotate(sublayertransform, metrics.radians, 0, 1, 0); sublayertransform = catransform3dtranslate(sublayertransform, 0, 0, metrics.translationpointsz);
how can create matching transform 1 using key-paths ?
looking @ 2 screenshots, , assuming you're going rotating cube effect , 2 screenshots taken @ different times in animation, looks top 1 has perspective on , bottom 1 not.
fixing simple matter of editing .m34 value of transform, small value such 1/500. there excellent write of here.
having done need apply translation steps before rotation, so:
catransform3d sublayertransform = catransform3dmaketranslation(0, 0, 0); sublayertransform.m34 = -0.000555; sublayertransform = catransform3dtranslate(sublayertransform, _currentmetrics.translationpointsx, 0, _currentmetrics.translationpointsz); sublayertransform = catransform3drotate(sublayertransform, _currentmetrics.radians, 0, 1, 0);
i've done similar used container view controller shift 1 next. when commenting on code thought i'd used z anchor point turns out didn't. here code use transition 1 view controller if rotating cube. may of interest. extract larger method, i've not missed vital.
cgrect newframe = self.containerview.bounds; uiview *outgoingview = _currentviewcontroller.view; uiview *incomingview = currentviewcontroller.view; incomingview.frame = newframe; [catransaction begin]; [catransaction setdisableactions:yes]; catransform3d parent = catransform3didentity; parent.m34 = -0.003; self.containerview.layer.sublayertransform = parent; bool righttoleft = (_currentviewcontroller == [self.viewcontrollers itembefore:currentviewcontroller]); cgfloat intranslatex = incomingview.bounds.size.width; cgfloat inrotation = m_pi_2; cgfloat inanchorx = 0.0; if (!righttoleft) { intranslatex = -intranslatex; inrotation = -inrotation; inanchorx = 1.0; } catransform3d int = catransform3dmaketranslation(intranslatex, 0.0, 0.0); int = catransform3drotate(int, inrotation, 0.0, 1.0, 0.0); cgrect previousframe = incomingview.frame; incomingview.layer.anchorpoint = cgpointmake(inanchorx, 0.5); incomingview.frame = previousframe; incomingview.layer.transform = int; incomingview.hidden = no; cgfloat outtranslatex = -outgoingview.bounds.size.width; cgfloat outrotation = -m_pi_2; cgfloat outanchorx = 1.0; if (!righttoleft) { outtranslatex = -outtranslatex; outrotation = -outrotation; outanchorx = 0.0; } catransform3d outt = catransform3dmaketranslation(outtranslatex, 0.0, 0.0); outt = catransform3drotate(outt, outrotation, 0.0, 0.5, 0.0); cgrect outgoingframe = outgoingview.frame; outgoingview.layer.anchorpoint = cgpointmake(outanchorx, 0.5); outgoingview.frame = outgoingframe; [catransaction commit]; [self transitionfromviewcontroller:_currentviewcontroller toviewcontroller:currentviewcontroller duration:0.4 options:uiviewanimationcurveeaseinout animations:^{ outgoingview.layer.transform = outt; incomingview.layer.transform = catransform3didentity; } completion:^(bool finished) { _currentviewcontroller = currentviewcontroller; outgoingview.layer.transform = catransform3didentity; self.imageview.image = currentviewcontroller.tabbaritem.image; self.viewselector.userinteractionenabled = yes; }];
for experimenting 3d transforms, have created little demo app allows build stack of transforms , see effects. it's available on github, , introduced here.
Comments
Post a Comment