29,028
社区成员
发帖
与我相关
我的任务
分享
什么意思,因为设置了anchorPoint而导致图片的frame的orgin改生了改变? 是不是附加动画后导致的位置改变?
var shake = CABasicAnimation(keyPath: "transform.rotation.z")
horse.layer.anchorPoint = CGPointMake(0.5, 0.8) // (0.5,0.5)是以图片为中心晃动 而(0.5,0.8)会上移下 然后晃动。这两中方法晃动中心是不变的,只是图片上移而产生晃动点往下
shake.fromValue = -0.2
shake.toValue = +0.2
shake.duration = 0.4
shake.autoreverses = true
shake.repeatCount = 4 //重复次数
// [yourView.layer setAnchorPoint:CGPointMake(0, 0)];
self.horse.layer.addAnimation(shake, forKey: "animateTransform")
imgView.layer.anchorPoint= CGPointMake(0.5, 0.8); 0.5是x不变,0.8是往上移动了。效果是可以实现了,但是图片位置发生改变了。
UIImageView *imgView =[ [UIImageView alloc] initWithImage:XXX];
imgView.layer.anchorPoint= CGPointMake(0.5, 0.8);
2. 设置好轴点,如何来实现旋转动画
这里建议使用CABasicAnimation 来完成动画,这里有个链接有可以看一下
http://www.cocoachina.com/bbs/read.php?tid=27152