iOS时钟实现
2019獨角獸企業重金招聘Python工程師標準>>>
#####時鐘實現 #####1.首先來看看總體效果 #####2.先來實現秒針的變化 #####2.1先來看效果圖片 #####2.2添加UIimageView加載圖片,然后添layer
-(void) setUpSecodLayer{CALayer *layer=[CALayer layer];CGFloat clockW=self.imageView.bounds.size.width;layer.position=self.imageView.center;layer.anchorPoint=CGPointMake(0.5, 1);layer.bounds=CGRectMake(0, 0, 1,clockW*0.5-20);layer.backgroundColor=[UIColor redColor].CGColor;self.secondLayer=layer;[self.view.layer addSublayer:layer]; }#####2.3添加一個定時器,不停旋轉
- (void)viewDidLoad {[super viewDidLoad];[self setUpSecodLayer];//[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeChange) userInfo:nil repeats:YES]; } -(void) timeChange{//獲取當前日歷對象NSCalendar *calendar=[NSCalendar currentCalendar];//獲取日期的組件:年月日時分秒//components:需要獲取的日期組件//formDate:獲取哪個日期的組件NSDateComponents *cmp=[calendar components:NSCalendarUnitSecond |NSCalendarUnitMinute | NSCalendarUnitHour fromDate:[NSDate date]];//獲取秒NSInteger second=cmp.second;//獲取分 // NSInteger minute=cmp.minute;//獲取小時 // NSInteger hour=cmp.hour;// // NSLog(@"%li",(long)second);CGFloat secondAngle=(second*6)*(M_PI*2)/360;self.secondLayer.transform=CATransform3DMakeRotation(secondAngle, 0, 0, 1);}#####3源代碼詳細地址
- github
轉載于:https://my.oschina.net/HYLApple/blog/707562
總結
- 上一篇: Object与RTTI
- 下一篇: Scala比较器:Ordered与Ord