Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 围绕中心点旋转UIView而不旋转视图本身_Ios_Objective C_Uiview_Quartz Core - Fatal编程技术网

Ios 围绕中心点旋转UIView而不旋转视图本身

Ios 围绕中心点旋转UIView而不旋转视图本身,ios,objective-c,uiview,quartz-core,Ios,Objective C,Uiview,Quartz Core,我希望围绕中心点旋转UIView,而不旋转UIView本身。所以更像是摩天轮上的汽车(总是保持直立),而不是时钟的指针 当我围绕中心点旋转UIView时,我使用层位置/锚点/变换来实现效果。但这显然改变了视图本身的方向 有什么帮助吗 keller您应该反复围绕一个圆重新定位视图的中心。实现一个计算当前中心点的方法,并从UIView animateWithDuration继续调用该方法。。。方法。这在核心动画中很容易做到。我在这个例子中使用了一些非常无聊的静态值,所以显然您需要进行一些修改。但这将

我希望围绕中心点旋转UIView,而不旋转UIView本身。所以更像是摩天轮上的汽车(总是保持直立),而不是时钟的指针

当我围绕中心点旋转UIView时,我使用层位置/锚点/变换来实现效果。但这显然改变了视图本身的方向

有什么帮助吗


keller

您应该反复围绕一个圆重新定位视图的中心。实现一个计算当前中心点的方法,并从UIView animateWithDuration继续调用该方法。。。方法。

这在核心动画中很容易做到。我在这个例子中使用了一些非常无聊的静态值,所以显然您需要进行一些修改。但这将向您展示如何沿圆形路径移动视图

UIView *view = [UIView new];
[view setBackgroundColor:[UIColor redColor]];
[view setBounds:CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
[view setCenter:[self pointAroundCircumferenceFromCenter:self.view.center withRadius:140.0f andAngle:0.0f]];
[self.view addSubview:view];

UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(CGRectGetMidX(self.view.frame) - 140.0f, CGRectGetMidY(self.view.frame) - 140.0f, 280.0f, 280.0f)];

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 5.0;

pathAnimation.path = [path CGPath];

[view.layer addAnimation:pathAnimation forKey:@"curveAnimation"];
以及生成视图初始中心的基本函数

- (CGPoint)pointAroundCircumferenceFromCenter:(CGPoint)center withRadius:(CGFloat)radius andAngle:(CGFloat)theta
{
    CGPoint point = CGPointZero;
    point.x = center.x + radius * cosf(theta);
    point.y = center.y + radius * sinf(theta);

    return point;
}