嘿,那里需要你的帮助,
我正在尝试为我的 iPhone 创建一个模拟时钟。问题是,UIImage 没有以正确的方式移动或没有移动,大多数时候它在整个视图中旋转。是否缺少任何框架,我将度数转换为弧度......这是代码:
#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