Iphone 是否围绕屏幕外的点旋转UIImageView?(图像视图的中心)

Iphone 是否围绕屏幕外的点旋转UIImageView?(图像视图的中心),iphone,ios,objective-c,rotation,quartz-graphics,Iphone,Ios,Objective C,Rotation,Quartz Graphics,嗨,我有一个部分在屏幕上,部分在屏幕下的UIImageView 我想围绕屏幕外的一个点(视图的中心)旋转视图 我该怎么做 fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; fullRotationAnimation.fromValue= [NSNumber numberWithFloat:0.0f]; fullRotationAnimat

嗨,我有一个部分在屏幕上,部分在屏幕下的UIImageView

我想围绕屏幕外的一个点(视图的中心)旋转视图

我该怎么做

fullRotationAnimation           = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotationAnimation.fromValue= [NSNumber numberWithFloat:0.0f];
    fullRotationAnimation.toValue   = [NSNumber numberWithFloat:2 * M_PI];
    fullRotationAnimation.duration  = 4;
    fullRotationAnimation.repeatCount = 1;
    [self->greyRings.layer addAnimation:fullRotationAnimation forKey:@"360"];
我现在正在使用这个代码,但它只是围绕屏幕中心旋转

有什么想法吗?

使用块动画:

- (void)rotateImageView:(UIImageView *)imageView aroundPoint:(CGPoint)point byAngle:(CGFloat)angle {

    CGFloat sinA = sin(angle);
    CGFloat cosA = cos(angle);
    CGFloat x = point.x;
    CGFloat y = point.y;

    CGAffineTransform transform = CGAffineTransformMake(cosA,sinA,-sinA,cosA,x-x*cosA+y*sinA,y-x*sinA-y*cosA);

    [UIView animateWithDuration:4.0 animations:^{
        imageView.transform = transform;
    }];
}
请注意,角度以弧度为单位,因此完全旋转为2.0*M_PI。

使用块动画:

- (void)rotateImageView:(UIImageView *)imageView aroundPoint:(CGPoint)point byAngle:(CGFloat)angle {

    CGFloat sinA = sin(angle);
    CGFloat cosA = cos(angle);
    CGFloat x = point.x;
    CGFloat y = point.y;

    CGAffineTransform transform = CGAffineTransformMake(cosA,sinA,-sinA,cosA,x-x*cosA+y*sinA,y-x*sinA-y*cosA);

    [UIView animateWithDuration:4.0 animations:^{
        imageView.transform = transform;
    }];
}

请注意,角度以弧度为单位,因此完全旋转为2.0*M_PI。

可能需要设置CALayer的锚点:有关详细信息,请参见

//(0,0) is the left-bottom of your layer bounds
self->greyRings.layer.anchorPoint = CGPointMake(0.0f, 0.0f);

我认为负主播点也应该起作用。所以你最好给出你的边界,我们可以为你计算。

也许你必须设置CALayer的主播点:有关更多详细信息,请参阅

//(0,0) is the left-bottom of your layer bounds
self->greyRings.layer.anchorPoint = CGPointMake(0.0f, 0.0f);

我认为负主播点也应该起作用。所以你最好给出你的界限,我们可以为你计算。

太棒了,谢谢你,我怎么才能找到ui图像视图的中心点?当然可以。cgpoint center=myImageView.center;(继承自UIView)太棒了,谢谢,我怎样才能找到ui图像视图的中心点?当然可以。cgpoint center=myImageView.center;(继承自UIView)UIImageView是976宽乘720高,水平和垂直放置在屏幕中心,谢谢。UIImageView是976宽乘720高,水平和垂直放置在屏幕中心,谢谢。