gpt4 book ai didi

ios - Objective-C CGAffineTransformRotate 不起作用

转载 作者:行者123 更新时间:2023-11-29 03:31:55 27 4
gpt4 key购买 nike

嘿,需要你的帮助,

我正在尝试为我的 iPhone 创建一个模拟时钟。问题是,UIImage 没有以正确的方式移动或没有移动,大多数时候它在整个 View 中旋转。是否缺少任何框架,我将度数转换为弧度...这是代码:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Getting a Timer
NSTimer *timer = [[NSTimer alloc]init];
timer = [NSTimer scheduledTimerWithTimeInterval: 1 target:self
selector:@selector(tick:) userInfo:nil repeats:YES];
[timer fire];
self.ticker = 0;
self.minutes = 0;
self.hours = 0;
}

- (void)tick:(NSTimer *)theTimer
{
//Turning Seconds into Minutes and Hours
self.ticker ++;
self.timerLabel.text = [NSString stringWithFormat:@"%d",self.ticker];
self.seconds = self.ticker;
if (self.seconds == 60){
self.ticker = 0;
self.seconds = 0;
self.minutes ++;
}
if (self.minutes == 60){
self.minutes = 0;
self.hours ++;
}

//Main issue here...
// 360° / 60 second = 6° per second
double grad = self.ticker * 6;
//Converting Grad into Rad
double rad = M_PI * grad / 180;
//Set Transformation ---> CGAffineTransformMakeRotation does not work eighter
CGAffineTransform transform = CGAffineTransformRotate(self.pointerImage.transform, rad);
//Set Transformation to UIImageView caleld pointerImage
self.pointerImage.transform = transform;
//self.pointerImage.center = CGPointMake(160, 420);
//NSLog(@"%f", grad);



if ( self.ticker == 60){
self.ticker = 0;
}

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

围绕圆心的旋转需要初始变换来偏移边界 - 因此变换位于圆心。您肯定会在此站点上找到示例代码。我强烈建议您创建一个单 View 项目,向其中添加一个彩色方形 View ,然后尝试使其正确旋转。然后才采用该代码并将其集成到您的实际项目中。

关于ios - Objective-C CGAffineTransformRotate 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657956/

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