初見IOS的UI之:UI控制項的屬性frame bounds center 和transform

來源:互聯網
上載者:User

標籤:style   class   c   ext   color   a   

這些屬性,內部都是結構體:CGRect CGPoint CGFloat

背景知識:所有的控制項都是view的子類,螢幕就是一個大的view;每個view都有個viewController,它是view的管家,每個view對應著一個viewController,來管理view。

  1.  frame & bounds & center

    ========================================

    1> frame可以修改對象的位置和尺寸

    2> bounds可以修改對象的尺寸

    3> center可以修改對象的位置,是對象的中心的x,y座標

 

  

  2.首尾式動畫

  ========================================

  // beginAnimations表示此後的代碼要“參與到”動畫中

  [UIView beginAnimations:nil context:nil];

  // setAnimationDuration用來指定動畫期間

  [UIView setAnimationDuration:2.0];

  self.headImageView.bounds = rect;

 

  // commitAnimations,將beginAnimation之後的所有動畫提交並產生動畫

  [UIView commitAnimations];

 

  3. transform屬性

  ========================================

  在OC中,通過transform屬性可以修改對象的平移、縮放比例和旋轉角度

 

  常用的建立transform結構體方法分兩大類

 

  1> 建立“基於控制項初始位置”的形變

  CGAffineTransformMakeTranslation

  CGAffineTransformMakeScale

  CGAffineTransformMakeRotation

 

  2> 建立“基於transform參數”的形變,返回的時當前的座標值,不需要一直計算,這個比較常用

  所以會多一個參數:就是當前的控制項對象;

  CGAffineTransformTranslate

  CGAffineTransformScale

  CGAffineTransformRotate

 

  補充:

  在OC中,所有跟角度相關的數值,都是弧度值,180° = M_PI

  正數表示順時針旋轉

  負數表示逆時針旋轉

  提示:由於transform屬性可以基於控制項的上一次的狀態進行疊加形變,例如,先旋轉再平移

  因此在實際動畫開發中,當涉及位置、尺寸形變效果時,大多修改控制項的transform屬性,

  而不是frame、bounds、center  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.