【发布时间】:2014-11-11 12:06:27
【问题描述】:
我正在尝试沿任意路径为按钮设置动画。为此,我需要创建一个路径,你正在使用 BezierPath。
但是,每当我将 moveToPoint 设置为 0,0 而不是从屏幕左上角开始动画时,就会发生一些奇怪的事情,按钮会出现在顶部和左侧,因此它只是部分可见。
这里发生了什么? moveToPoint 是否使用其他坐标系?
按钮的锚点设置为标准的左上角。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
bezierPath = [[UIBezierPath alloc]init];
[bezierPath moveToPoint:CGPointMake(0, 0)];
[bezierPath addLineToPoint:CGPointMake(52, 83)];
[bezierPath addLineToPoint:CGPointMake(45, 59)];
[bezierPath addLineToPoint:CGPointMake(65, 30)];
}
-(void)randomAnimation
{
CAKeyframeAnimation* keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyframeAnimation.duration = 4.0;
keyframeAnimation.path = [bezierPath CGPath];
[self.rndBtn.layer addAnimation:keyframeAnimation forKey:@"position"];
}
【问题讨论】:
标签: ios objective-c uibutton core-animation uibezierpath