麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

雜記---不定期更新

2019-11-14 18:18:21
字體:
來源:轉載
供稿:網友

注:再本文中您將可能看到排版混亂,中英文混用,表達不清等問題,敬請見諒。中英文混用是因為我想保留英文的意思,避免錯翻譯(其實是我英文水平不夠根本就不知道什么意思)

------------------------------------------------------------- 碎 片 知 識 ----------------------------------------------------------------------------

1.data source也是一種特殊的delegate,data source負責傳輸數據給View例如data、at、count等,而delegate負責處理View的did、should、will等問題,View把需要的數據信息或者事件信息傳輸給dalegate,dalegate則負責回復這些信息。

--------------------------------------------------------------- Block -------------------------------------------------------------------------------

1.Block當中不能修改局部變量的值,在block中,局部變量都是只讀的,比如在block外部有一個BOOL value = YES;,如果在block內部修改value的值,這就是非法的,編譯器會報錯。當然,有一種辦法可以進行讀寫,就是在變量前面加上兩個下劃線和block,如:__block BOOL value = YES;,這樣就可以在block當中進行該變量的讀寫了。

int anInteger = 42;void (^testBlock)(void) = ^{    NSLog(@"Integer is: %i", anInteger);};anInteger = 84;testBlock();// 輸出結果為:Integer is: 42// It also means that the block cannot change the value of the original variable// 在block defined的那一刻anInteger的值就已經被捕獲了
輔助理解

原理是如果聲名了__block,編譯器就會生成一段代碼將value從棧(stack)移到堆中(heap),同時編譯器會有一個強指針指向block中的每一個變量,確保它不會在block執行完畢前就離開堆,當執行完block的時候,編譯器將信息拷貝回堆當中,然后再移回棧當中,同時強指針會在block goes out of scope*1之前一直存在。

2.如果block不需要參數,參數的括號可以直接省去,如果返回值再return的時候可以直接看出來,比如return [MyClass isKindOfClass:...];,這種類型的編譯器會自動完成返回值,所以block的返回值類型也可以省去。

--------------------------------------------------------------- 動 畫 --------------------------------------------------------------------------------

1.使用animateWithDuration來執行動畫的時候如果動畫被中途中斷了,比如說將alpha從1.0設置為0,如果執行中途有代碼或者另一個動畫設置了alpha,則Completion的block的參數finished則為NO,如果沒有人中斷完成了動畫,則finished為YES。

2.UIViewAnimationOptions:

  1. BeginFromCurrentState:如果開啟了該選項,如果執行第一個動畫將alpha變為0,在執行到變為0.5的時候(雖然代碼是立即變為0,但是此處為看到的動畫),如果動畫二將alpha變為1,并且開啟了這個選項,則alpha會從0.5開始變為1。如果沒有開啟則會從0開始變為1。
  2. CurveEaseInEaSEOut和CurveEaseIn:如果開啟了該選項,則會在執行動畫的時候使用線性運動(開始慢,中間加速,結束慢)。

3.使用transitionWithView:(UIView *)view              方法來修改整個視圖的狀態。

        duration:(NSTimeIntevel)duration

        options:(UIViewAnimationOptions)options

        animations:(void (^)(void))animations

        completion:(void (^)(BOOL finished))completion;

4.transitionWithView的options:

  1. UIViewAnimationOptionsTransitionFlipFrom{Left, Right, Top, Bottom},代表翻轉整個View(選項是從哪個地方翻轉)。
  2. UIViewAnimationOptionsTransitionCrossDissolve,代表交叉溶解。
  3. UIViewAnimationOptionsTransitionCurl{Up, Down},代表從哪個方向卷起。

5.transitionFromView:(UIView *)fromView            使用toView取代fromView。

        toView:(UIView *)toView

        duration:(NSTimeInteval)duration

        options:(UIViewAnimationOptions)options

        completion:(void (^)(BOOL finished))completion;

--------------------------------------------------------- DynamicAnimator -------------------------------------------------------------------------

1.創建動力動畫的步驟:

  1. 創建一個UIDynamicAnimator對象。
  2. 給它加入UIDynamicBehaviors(gravity, collisions, etc)。
  3. 給UIDynamicBehaviors加入UiDynamicItems。

2.創建UIDynamicAnimator對象的時候直接使用alloc/init是可以的,但是如果作用于一個UIView對象則需要使用alloc/initWithReferenceView:方法來指定頂級視圖。UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:aView];

3.創建UIDynamicBehavior的時候直接使用alloc/init就可以了,然后將其加入UIDynamicAnimator中。UIGravityBehavior *gravity = [[UIGravity Behavior alloc] init];[animator addBehavior:gravity];

4.添加Item:id <UIDynamicItem> item1 = ...;[gravity addItem:item1];基本上90%的item都是UIView。

5.UIDynamicItem協議屬性方法:

  1. @PRoperty (readonly) CGRect bounds;
  2. @property (readwirte) CGPoint center;
  3. @property (readwrite) CGAffineTransform transform;

6.如果要在animator執行動畫的時候修改item的屬性,必須要使用- (void)updateItemUsingCurrentState:(id <UIDynamicItem>)item;方法,不然animator會忽略所有其他的修改。

7.UIGravityBehavior(重力行為--控制Items的角度以及重力系數)屬性方法:

  1. @property CGFloat angle;
  2. @property CGFloat magnityde; // 1.0 is 1000 points/second/square

8.UICollisionBehavior(碰撞行為--行為中的Items碰撞在一起的時候會撞開,和現實中碰撞一樣,同時可以設置邊界,置頂彈力大小或者密度)屬性方法:

  1. @property UICollisionBehaviorMode collisionMode; // Items, boundaries, Everything(default)
  2. - (void)addBoundaryWithIdentifier:(NSString *)identifier for Path:(UIBezierPath *)path; // 增加邊界
  3. @property BOOL translatesReferenceBoundsIntoBoundary; // 將其設為YES,則會將animator的referenceView的邊界作為邊界

9.UIAttachmentBehavior(吸附行為--默認情況下吸附兩者之間的間距想一個鐵棒,通過對其阻尼大小(damping)和震蕩頻率(oscillation)進行設置可以使其變得想彈簧一樣)屬性方法:

  1. - (instancetype)initWithItem:(id <UIDynamicItem>)item attachedToAnchor:(CGPoint)anchor;
  2. - (instancetype)initWithItem:(id <UIDynamicItem>)item1 attachedToItem:(id <UIDynamicItem>)item2;
  3. - (instancetype)initWithItem:(id <UIDynamicItem>)item offsetFromCenter:(CGPoint)offset...
  4. @property (readwrite) CGFloat length; // 兩個吸附物之間的間距
  5. 同時也可是設置阻尼以及震蕩頻率
  6. @property (readwrite) CGPoint anchorPoint; // 能隨時重新設置

10.UISnapBehavior(速甩行為我覺得這個翻譯實在是不好)屬性方法:

  1. - (instancetype)initWithItem:(id <UIDynamicItem>)item snapToPoint:(CGPoint)point; // 可以想象成在移動到新位置的時候item的四個角都有彈簧,它會晃一下來給予用戶反饋(哦!我到達了!)

11.UIPushBehavior(推動行為)屬性方法:

  1. @property UIPushBehaviorMode mode;
  2. @property CGVector pushDirection;
  3. @property CGFloat magnitude/angle; // 將magnitude設置為1.0將會使用100 points/second/squared 移動100x100的view

12.UIDynamicItemBehavior(動力項行為--如果想要設置了例如摩擦力、彈力、密度等,不管進行什么行為,它的這些屬性應該是一樣的,他們都是在UIDynamicItemBehavior類中設置)屬性方法:

  1. @property BOOL allowsRotation; // 是否可以旋轉
  2. @property BOOL friction; // 摩擦力
  3. @property BOOL elasticity; // 彈力
  4. @property CGFloat density; // 密度
  5. - (CGPoint)linearVelocityForItem:(id <UIDynamicItem>)item; // 獲得動力項不同方向的速度
  6. - (CGPoint)angularVelocityForItem:(id <UIDynamicItem>)item; // 獲得動力項不同角度的速度

13.UIDynamicBehavior是所有行為的子類。可以使用- (void)addChildBehavior:(UIDynamicBehavior *)behavior;方法來添加子行為。

14.所有的behaviors都擁有一個屬性@property UIDynamicAnimator *dynamicAnimator;它們記錄的是所屬UIDynamicAnimator的信息。同時擁有一個方法- (void)willMoveToAnimator:(UIDynamicAnimator *)animator;,該方法會在behavior加入到animator或者移出的時候被調用,加入的時候參數是目標animator,移除的時候參數會被設置成nil。

15.UIDynamicBehavior的action property:@property (copy) void (^action)(void) 想要使用這個屬性,只要使用任意behavior加上.action并且賦值一個block,那么在每次執行behavior的時候都會進行調用該block。

 --------------------------------------------------------------- 多 線 程 ----------------------------------------------------------------------------

1.線程可以理解為queue,queue中都是blocks。

2.MainQueue存儲的是需要改變屏幕顯示或者同步(讓一切改變和UI同步)等操作的block。

3.在另一個線程執行block:

  1. dispatch_queue_t queue = ...; // typedef 類型
  2. dispatch_async(queue, ^{  }); // 將目標隊列以及要執行的block作為參數傳入

4.獲得主要線程:

  1. dispatch_queue_t queue = dispatch_get_main_queue();
  2. NSOperationQueue *mainQ = [NSOperationQueue mainQueue]; // for object-oriented APIs

5.dispatch_queue_t otherQ = dispatch_queue_create("name", NULL); // 第一個是queue的名字,第二個則是指定queue是serial queue(串行隊列)或者concurrent queue(并發隊列),NULL代表是一個serial queue

6.將block放回主線程:

 - (void)performSelectorOnMainThread:(SEL)aMethod

              withObject:(id)obj    // selector方法的參數,可以為nil

            waitUntilDone:(BOOL)waitUntilDone; // is whether you're gonna wait until this thing gets pulled off the main queue and run on the main queue and then finishes before this thread, that's calling this, goes or not.                                   (英文部分不是很理解),通常設置為NO,不需要等待,會直接再主隊列上調用這個方法, 輪到它執行的時候就執行

 dispatch_async(dispatch_get_main_queue(), ^{ /* call aMethod */ })  

7.使用多線程的例子:

  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL urlWithString:@"http://..."]];

  NSURLConfiguration *configuration = ...;

  NSURLsession *session = ...;

  NSURLSessionDownloadTask *task;

  task = [session downloadTaskWithRequest:request

                completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error) {

  /* want to do UI things here can I? */ /* must be main queue */

  }];

  [task resume];

8.創建Session的方法:

  NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration

                                delegate:nil

                             delegateQueue:[NSOperationQueue mainQueue]];

  NSURLSessionDownloadTask *task;

  task = [session downloadTaskWithRequest:request

              completionHandler:^(NSURL *localfile, NSURLResponse *response, NSErr or *error) {

    / * yes, can do UI things directly because this is called on the main queue */

  }];

  [task resume];

9.沒有代理以及代理線程的創建session方法

  NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; // no delegateQueue

  NSURLSessionDownloadTask *task;

  task = [session downloadTaskWithRequest:request

               completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error) {

    disapatch_async(dispatch_get_main_queue(), ^( /* do UI things */ ));

    or [self performSelectorOnMainThread:@selector(doUIthings) withObject:nil waitUntilDone:NO];

  }];

  [task resume];

10.ScrollView獲得當前顯示區域在整個ScollView中的坐標

  CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:subview];

11.- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated; // 對rect進行盡可能的方法或者縮小(顯示在屏幕上)

 ------------------------------------------------------------- 表格視圖和iPad --------------------------------------------------------------------------

 


突然感覺學的好像有點快了,開始回頭看以前知識的詳細解釋。

*1:英語不是很好,我的理解是block也是有作用域的,比如[UIView animateWithDuration:NSTimeInterval animations:^(void)animations]這個方法,再執行完該方法的時候可能block就已經失效了,block的作用與就是這一條語句,當然這是我的猜測,如有了解的請務必糾正我。

 

火狐的restart命令會讓博客園自動保存內容全部掛掉?明明自動保存了為什么重啟后讀取保存的幾個小時前的數據?寫了幾個小時就這么沒了,瞬間不想再寫博客了。

還是屈服了,從第4點開始可能記得有點亂,因為之前記了很多結果被該死的自動保存干掉了...

 

有點亂,分個類先


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 一级大黄毛片免费观看 | 激情视频导航 | 成人不卡一区二区 | 一本一道久久久a久久久精品91 | 日本视频免费观看 | 色婷婷一区二区三区 | 免费观看9x视频网站在线观看 | 插插操 | 成码无人av片在线观看网站 | 精品久久久久久久 | 黄色av电影在线播放 | 永久免费黄色大片 | 99国产精品国产免费观看 | 精精国产xxxx视频在线野外 | 黄色高清免费 | 毛片在线视频在线播放 | 亚洲午夜久久久久 | 国产宾馆3p国语对白 | 羞羞视频免费网站 | 狠狠干最新网址 | 婷婷久久综合九色综合色多多蜜臀 | 男男羞羞视频网站国产 | 国产精品视频一区二区噜噜 | 日本在线免费观看视频 | 国产二区三区在线播放 | 欧美视频一区二区三区四区 | 国产黄色一级大片 | 久久久精品综合 | 久久久三区 | 国产日产精品一区二区三区四区 | 一级一级一级一级毛片 | 国产精品色综合 | 国产精品视频一区二区噜噜 | 久久蜜桃香蕉精品一区二区三区 | 羞羞视频免费视频欧美 | 久久久久久久一区二区三区 | 日本成年网| 91成人免费在线视频 | 91精品国产91久久久久久不卞 | 91一区二区在线观看 | 操碰视频在线观看 |