代码之家  ›  专栏  ›  技术社区  ›  Skyler

在iPhone的Quartz 2D中进行旋转变换时,我可以移动原点吗?

  •  8
  • Skyler  · 技术社区  · 17 年前

    // Before this i'd make a call to a function that draws a path to a passed in context
    CGAffineTransform inverseTranslation = CGAffineTransformMakeTranslation( transX, transY );
    CGAffineTransform translation = CGAffineTransformMakeTranslation( -transX, -transY );
    CGAffineTransform rot = CGAffineTransformMakeRotation( 3.14 );
    CGAffineTransform final = CGAffineTransformConcat( CGAffineTransformConcat( inverseTranslation, rot ), translation );
    // Then i apply the transformation animation like normal using self.transform = final etc etc
    

    我也尝试过CGContextTranslateTM和CGContextSaveGState/UIGraphicsPushContext,但这些似乎收效甚微。

    我已经为此奋斗了好几天,我目前的解决方案似乎很接近,但我不知道如何摆脱翻译推文。有人对此有解决方案或更好的方法吗?

    4 回复  |  直到 17 年前
        1
  •  14
  •   Matthieu Riegler    12 年前

    CGSize sz = theview.bounds.size;
    // Anchorpoint coords are between 0.0 and 1.0
    theview.layer.anchorPoint = CGPointMake(rotPoint.x/sz.width, rotPoint.y/sz.height);
    [UIView beginAnimations:@"rotate" context:nil];
    theview.transform = CGAffineTransformMakeRotation( 45. / 180. * M_PI );
    [UIView commitAnimations];
    

    http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html

        2
  •  7
  •   Abramodj    14 年前

    CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
    transform = CGAffineTransformRotate(transform, angle);
    transform = CGAffineTransformTranslate(transform,-x,-y);
    

    (x,y)

        3
  •  2
  •   duncanwilcox    17 年前

    [UIView beginAnimations:@"rotate" context:nil];
    self.transform = CGAffineTransformMakeRotation( 45. / 180. * 3.14 );
    [UIView commitAnimations];
    
        4
  •  1
  •   Kriem    17 年前

    CGFloat newRotation = 3.14f 
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0]; // no tweening
    CGAffineTransform transform = CGAffineTransformMakeRotation(newRotation);
    self.transform = transform;
    [UIView commitAnimations];