iphone – 图层位置在(核心)动画的开头跳转

iphone – 图层位置在(核心)动画的开头跳转,第1张

概述所以,我正在尝试创建一个平铺翻转效果,就像在 Windows Phone 7上一样. 到目前为止,我有以下代码,但我有几个问题. CALayer *layer = self.theRedSquare.layer;CATransform3D initialTransform = self.theRedSquare.layer.transform;initialTransform.m34 = 1. 所以,我正在尝试创建一个平铺翻转效果,就像在 Windows Phone 7上一样.

到目前为止,我有以下代码,但我有几个问题.

CALayer *layer = self.theRedSquare.layer;CAtransform3D initialtransform = self.theRedSquare.layer.transform;initialtransform.m34 = 1.0 / -1000;[UIVIEw beginAnimations:@"Scale" context:nil];[UIVIEw setAnimationDuration:1];[UIVIEw setAnimationCurve: UIVIEwAnimationCurveEaseInOut];layer.transform = initialtransform;layer.anchorPoint = CGPointMake(-0.3,0.5);CAtransform3D rotationAndPerspectivetransform = self.theRedSquare.layer.transform;rotationAndPerspectivetransform = CAtransform3DRotate(rotationAndPerspectivetransform,M_PI,-self.theRedSquare.bounds.size.height/2,0);layer.transform = rotationAndPerspectivetransform;[UIVIEw setAnimationDelegate:self];[UIVIEw commitAnimations];

为什么我的红色方块(一个简单的UI视图)在动画开始时转换为右边?

2.对于锚点,是否可以在父视图上设置位置?目前我正在相对于当前视图任意设置它.

提前感谢任何指针.

在动画之前

在动画期间(注意方块向右移动)

动画后(注意方块向右移动)

视频已添加:example video

解决方法
-(voID)setAnchorPoint:(CGPoint)anchorPoint forVIEw:(UIVIEw *)vIEw{    CGPoint newPoint = CGPointMake(vIEw.bounds.size.wIDth * anchorPoint.x,vIEw.bounds.size.height * anchorPoint.y);    CGPoint oldPoint = CGPointMake(vIEw.bounds.size.wIDth * vIEw.layer.anchorPoint.x,vIEw.bounds.size.height * vIEw.layer.anchorPoint.y);    newPoint = CGPointApplyAffinetransform(newPoint,vIEw.transform);    oldPoint = CGPointApplyAffinetransform(oldPoint,vIEw.transform);    CGPoint position = vIEw.layer.position;    position.x -= oldPoint.x;    position.x += newPoint.x;    position.y -= oldPoint.y;    position.y += newPoint.y;    vIEw.layer.position = position;    vIEw.layer.anchorPoint = anchorPoint;}-(voID)animateVIEw:(UIVIEw *)theRedSquare{    CALayer *layer = theRedSquare.layer;    CAtransform3D initialtransform = theRedSquare.layer.transform;    initialtransform.m34 = 1.0 / -1000;    [self setAnchorPoint:CGPointMake(-0.3,0.5) forVIEw:theRedSquare];    [UIVIEw beginAnimations:@"Scale" context:nil];    [UIVIEw setAnimationDuration:1];    [UIVIEw setAnimationCurve: UIVIEwAnimationCurveEaseInOut];    layer.transform = initialtransform;    CAtransform3D rotationAndPerspectivetransform = theRedSquare.layer.transform;    rotationAndPerspectivetransform = CAtransform3DRotate(rotationAndPerspectivetransform,-theRedSquare.bounds.size.height/2,0);    layer.transform = rotationAndPerspectivetransform;    [UIVIEw setAnimationDelegate:self];    [UIVIEw commitAnimations];}

取自这个,并稍微调整..希望它有所帮助
Changing my CALayer’s anchorPoint moves the view

总结

以上是内存溢出为你收集整理的iphone – 图层位置在(核心)动画的开头跳转全部内容,希望文章能够帮你解决iphone – 图层位置在(核心)动画的开头跳转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1083280.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存