【问题标题】:bezierPath moveToPoint wrong coordinate systembezierPath moveToPoint 坐标系错误
【发布时间】: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


    【解决方案1】:

    您正在为图层的位置属性设置动画,默认情况下该属性设置为图层的中心。如果您将按钮图层的中心设置为 0,0,它将在屏幕边缘居中,并且处于半关闭状态。

    您需要将起点设置为宽度/2,高度/2。或者,您可以移动图层的锚点,但这有副作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多