iOS時鐘開發案例分享

2022-09-25 03:33:08 字數 1472 閱讀 3328

思路就是利用calayer的隱式動畫來實現。因為uiview的非根層也就是手動建立的layer在其屬性發生變化時會缺省會產生動畫效果,這些屬性也叫作可動畫屬性。比如bounds、backgroundcolor、position。

時鐘裡面表盤就是乙個uiview,而三根針就是三個手動建立的layer。

先在storyboard上弄乙個uiimageview,設定表盤

然後在viewdidload中初始化三根針,並設定定時器,獲取當前時間,將當前時間對應的時針分針秒針分別指向對應的角度。

//// viewcontroller.m

// 時鐘效果

//// created by daniel on 16/4/7.

// copyright © 2023年 daniel. all rights reserved.//

#define kclockwh _clockview.bounds.size.width

//一秒鐘秒針轉多少度

#define preseconda 6

//一分鐘分針轉多少度

#define preminutea 6

//一小時時針轉多少度

#define prehoura 30

//每分鐘時針轉多少度

#define prehourminute 0.5

//每秒鐘分針轉多少度

#define preminutesecond 0.1

#define angle2raditon(a) ((a) / 180.0 * m_pi)

#import "viewcontroller.h"

@inte***ce viewcontroller ()

@property (weak, nonatomic) iboutlet uiimageview *clockview;

/** 秒針 */

@property(nonatomic, strong) calayer *secondl;

/** 分針 */

@property(nonatomic, strong) calayer *minutel;

/** 時針 */

@property(nonatomic, strong) calayer *hourl;

@end

@implementation viewcontroller

- (void)viewdidload

- (void)timechange

#pragma mark - 初始化時針

- (void)setuphourlayer

#pragma mark - 初始化分針

- (void)setupminutelayer

#pragma mark - 初始化秒針

- (void)setupsecondlayer

@end

效果圖:

本文標題: ios時鐘開發案例分享

本文位址:

Hive UDF開發案例

bin hive中操作 臨時函式的使用 add jar home hadoop lib train 1.0 snapshot.jar 將上傳的jar包匯入到classpath變數裡 list jars 檢視匯入的jar包 create temporary function say hello as ...

移動端開發案例

touchstart touchmove touchend 可以實現拖動元素 但是拖動元素需要當前手指的座標值 我們可以使用 targettouches 0 裡面的pagex 和 pagey 移動端拖動的原理 手指移動中,計算出手指移動的距離。然後用盒子原來的位置 手指移動的距離 手指移動的距離 手...

MIS系統開發案例

一 專案背景 本專案是為一家電視配件生產廠家做mis系統,該公司規模比較大,其產品在國內市場占有半數以上份額。本期專案是二期工程,系統的一期工程也是我公司做的,由於在使用上存在一些問題,啟動二期工程做優化和改進。二 專案特點 1 開發周期 從簽訂合同到驗收週期為1年 2 工作組成員 1個專案經理 在...