繁体   English   中英

围绕屏幕外的某个点旋转UIImageView? (uiImageView的中心

[英]Rotate a UIImageView around a point off screen? (center of uiImageView

嗨,我有一个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。

也许您必须设置CALayer的anchorPoint:有关更多详细信息,请参见指定图层的几何

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

我认为否定的anchorPoint也应该起作用。 因此,您最好尽自己所能,我们可以为您计算。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM