日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS的pch文件,NSTimer定时器,运行消息循环,随机色使用

發布時間:2023/12/18 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS的pch文件,NSTimer定时器,运行消息循环,随机色使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS的pch文件,NSTimer定時器,運行消息循環,隨機顏色獲取使用

xcode新創建一個項目命名pchTest
右鍵創建文件,選擇other 下面的pch,名字不要管默認就好

選中項目 : Buding Setting 搜索框輸入 Prefix

Prefix Header 雙擊一下,有個模態彈框,直接把pch往里面拖,xocde軟件會自動讀取到文件的路徑。直接運行就好了
Precompile Prefix Header 默認是NO,設置成YES,可以提高預編譯速度,相當于把pch文件的代碼加入緩存里面
storyBoard拖入一個按鈕. 拖動到點m文件里面,給action起個名字,我起成stop
PCH文件默認的全部刪掉加入

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#define AHLJColor(r,g,b) [UIColor colorWithRed:?/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define AHLJRandomColor AHLJColor(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))

這是隨機顏色

ViewController.m關鍵性code
#import “ViewController.h”
@interface ViewController ()
@property(nonatomic,weak)NSTimer *ti;
@end
@implementation ViewController

  • (IBAction)stop:(id)sender {
    [self.ti invalidate];
    }
  • (void)viewDidLoad {
    [super viewDidLoad];
    self.title = demo;
    self.view.backgroundColor = AHLJColor(144, 144, 122);
    }
  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeBg) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    self.ti = timer;
    }
    -(void)changeBg{
    self.view.backgroundColor = AHLJRandomColor;
    }
    @end

點擊屏幕可以改變屏幕顏色,以及重復時間設置,點擊按鈕可以停掉定時器。

總結

以上是生活随笔為你收集整理的IOS的pch文件,NSTimer定时器,运行消息循环,随机色使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。