gpt4 book ai didi

ios - UIImageView 不围绕中心旋转而是在整个地方跳跃

转载 作者:行者123 更新时间:2023-11-29 02:58:03 24 4
gpt4 key购买 nike

我有一个测试罗盘 VC,带有众所周知的罗盘图像 (128 x 128),中央坐标为 128,160。当我旋转 iPhone 时,指南针正确移动但到处乱跳。

我曾尝试从偏执狂中插入额外的代码以强制它保持在中心边界内,但似乎没有任何区别。

有什么想法吗?

-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading*)newHeading {
if (newHeading.headingAccuracy > 0) {
self.currentHeading = newHeading;
self.trueHeadingLabel.text = [NSString stringWithFormat:@"%d", (int)newHeading.trueHeading];
self.magneticHeadingLabel.text = [NSString stringWithFormat:@"%d", (int)newHeading.magneticHeading];
float heading = -((newHeading.magneticHeading*M_PI)/180.0f);

// Additional code to force image starts here
self.arrowImage.frame = CGRectMake(128,160,128,128);
self.arrowImage.layer.anchorPoint = CGPointMake(0.5,0.5);
self.arrowImage.center = CGPointMake(160,160);
// Additional code to force image ends here

self.arrowImage.transform = CGAffineTransformMakeRotation(heading);
}
}

最佳答案

您是否尝试过将 View 的 anchor 设置到它的中心?这应该导致围绕中心而不是围绕(0,0)旋转。你可以尝试一些代码:

[自层].anchorPoint = CGPointMake(width/2, height/2);

关于ios - UIImageView 不围绕中心旋转而是在整个地方跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23647200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com