無標(biāo)題文章

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

self.window = UIWindow(frame: UIScreen.main.bounds)

self.window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

self.window?.makeKeyAndVisible()

self.window?.rootViewController = UIViewController()

let redView = UIView(frame: CGRect(x: 107, y: 268, width: 200, height: 200))

redView.backgroundColor = UIColor.red

redView.tag = 200

self.window?.addSubview(redView)

redView.layer.cornerRadius = 100

let yelloView = UIView(frame: CGRect(x: 132, y: 293, width: 150, height: 150))

yelloView.backgroundColor = UIColor.yellow

yelloView.tag = 201

self.window?.addSubview(yelloView)

yelloView.layer.cornerRadius = 75

let blueView = UIView(frame: CGRect(x: 157, y: 318, width: 100, height: 100))

blueView.backgroundColor = UIColor.blue

blueView.tag = 202

self.window?.addSubview(blueView)

blueView.layer.cornerRadius = 50

//參數(shù)1:定時(shí)執(zhí)行的間隔

//參數(shù)2:目標(biāo)對(duì)象

//參數(shù)3:目標(biāo)對(duì)象選擇執(zhí)行的方法

//參數(shù)4:用戶信息 nil

//參數(shù)5:定時(shí)器是否重復(fù)執(zhí)行

Timer.scheduledTimer(timeInterval: 0.8, target: self, selector:#selector(changeColor), userInfo: nil, repeats: true)

return true

}

//MARK:-定時(shí)器找到目標(biāo)對(duì)象執(zhí)行的方法

func changeColor(){

let redView = self.window?.viewWithTag(200)

//存儲(chǔ)redView背景顏色

let color = redView?.backgroundColor

self.window?.viewWithTag(200)?.backgroundColor = self.window?.viewWithTag(201)?.backgroundColor

self.window?.viewWithTag(201)?.backgroundColor = self.window?.viewWithTag(202)?.backgroundColor

self.window?.viewWithTag(202)?.backgroundColor = color

}

func applicationWillResignActive(_ application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

func applicationDidEnterBackground(_ application: UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(_ application: UIApplication) {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(_ application: UIApplication) {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(_ application: UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市外盯,隨后出現(xiàn)的幾起案子摘盆,更是在濱河造成了極大的恐慌,老刑警劉巖饱苟,帶你破解...
    沈念sama閱讀 211,290評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件孩擂,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡箱熬,警方通過查閱死者的電腦和手機(jī)类垦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來城须,“玉大人蚤认,你說我怎么就攤上這事「夥ィ” “怎么了砰琢?”我有些...
    開封第一講書人閱讀 156,872評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)良瞧。 經(jīng)常有香客問我陪汽,道長(zhǎng),這世上最難降的妖魔是什么褥蚯? 我笑而不...
    開封第一講書人閱讀 56,415評(píng)論 1 283
  • 正文 為了忘掉前任挚冤,我火速辦了婚禮,結(jié)果婚禮上赞庶,老公的妹妹穿的比我還像新娘训挡。我一直安慰自己澳骤,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評(píng)論 6 385
  • 文/花漫 我一把揭開白布舍哄。 她就那樣靜靜地躺著宴凉,像睡著了一般。 火紅的嫁衣襯著肌膚如雪表悬。 梳的紋絲不亂的頭發(fā)上弥锄,一...
    開封第一講書人閱讀 49,784評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音蟆沫,去河邊找鬼籽暇。 笑死,一個(gè)胖子當(dāng)著我的面吹牛饭庞,可吹牛的內(nèi)容都是我干的戒悠。 我是一名探鬼主播,決...
    沈念sama閱讀 38,927評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼舟山,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼绸狐!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起累盗,我...
    開封第一講書人閱讀 37,691評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤寒矿,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后若债,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體符相,經(jīng)...
    沈念sama閱讀 44,137評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評(píng)論 2 326
  • 正文 我和宋清朗相戀三年蠢琳,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了啊终。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,622評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡傲须,死狀恐怖蓝牲,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情泰讽,我是刑警寧澤搞旭,帶...
    沈念sama閱讀 34,289評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站菇绵,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏镇眷。R本人自食惡果不足惜咬最,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望欠动。 院中可真熱鬧永乌,春花似錦惑申、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至望几,卻和暖如春绩脆,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背橄抹。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國(guó)打工靴迫, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人楼誓。 一個(gè)月前我還...
    沈念sama閱讀 46,316評(píng)論 2 360
  • 正文 我出身青樓玉锌,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親疟羹。 傳聞我的和親對(duì)象是個(gè)殘疾皇子主守,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容