大佬教程收集整理的这篇文章主要介绍了ios – 核心动画围绕点旋转,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
相对于从该点前进的设备计算旋转角度.
- (void)viewDidLoad{ [super viewDidLoad]; locationManager=[[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.headingFilter = 1; locationManager.delegate=self; [locationManager startUpdatingheading]; [locationManager startUpdatingLocation]; compassImage.layer.anchorPoint=CGPointZero; } - (void)locationManager:(CLLocationManager *)manager didUpdateheading:(CLheading *)newheading{ // Convert Degree to Radian and move the needle float oldRad = -manager.heading.trueheading * M_PI / 180.0f; float newRad = -newheading.trueheading * M_PI / 180.0f; CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"]; theAnimation.fromValue = [NSNumber numberWithFloat:oldRad]; theAnimation.toValue=[NSNumber numberWithFloat:newRad]; theAnimation.duration = 0.5f; [compassImage.layer addAnimation:theAnimation forKey:@"animateMyRotation"]; compassImage.transform = CGAffineTransformMakeRotation(newRad); NSLog(@"%f (%f) => %f (%f)",manager.heading.trueheading,oldRad,newheading.trueheading,newRad); }
我如何通过alpha旋转UIImageView(x,y)?
您只需要知道锚点也会影响图层在屏幕上的显示位置.更改定位点时,还必须更改位置以使图层显示在屏幕上的相同位置.
假设图层已经放置在它的起始位置并且周围的旋转点已知,则可以像这样计算锚点和位置(注意锚点位于图层边界的单位坐标空间中(意思是x和y在范围内的范围从0到1)):
CGPoint rotationPoint = // The point we are rotating around CGFloat minX = CGRectGetMinX(view.frame); CGFloat minY = CGRectGetMinY(view.frame); CGFloat width = CGRectGetWidth(view.frame); CGFloat height = CGRectGetHeight(view.frame); CGPoint anchorPoint = CGPointMake((rotationPoint.x-minX)/width,(rotationPoint.y-minY)/height); view.layer.anchorPoint = anchorPoint; view.layer.position = rotationPoint;
然后,您只需对其应用旋转动画,例如:
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotate.toValue = @(-M_PI_2); // The angle we are rotating to rotate.duration = 1.0; [view.layer addAnimation:rotate forKey:@"myRotationAnimation"];
请注意,您已更改了锚点,因此位置不再位于框架的中心,如果应用其他变换(例如比例),它们也将相对于锚点.
以上是大佬教程为你收集整理的ios – 核心动画围绕点旋转全部内容,希望文章能够帮你解决ios – 核心动画围绕点旋转所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。