iOS UIView屬性動畫和常用方法

2021-06-28 13:46:20 字數 1441 閱讀 5686

一、動畫的屬性是指當屬性從乙個值變為另乙個值的時候,可以半自動的支援動畫。

1.uiview物件中支援動畫的屬性有:

frame:改變檢視的尺寸和位置

bounds:改變檢視的尺寸

center:改變檢視的位置

transform:使用這個可以翻轉或者縮放試圖

alpha:使用這個可以改變檢視的透明度

backgroundcolor:使用這個來改變檢視的背景色

contentstetch:使用這個可以改變檢視的內容如何拉伸

2.配置動畫的引數

用setanimationstartdate:方法來設定動畫在commitanimations方法返回之後的發生日期;

用setanimationdelay:方法來設定實際發生動畫和commitanimations方法返回的時間點之間的間隔;

setanimationduration:方法來設定動畫持續的秒數;

setanimationcurve:方法來設定動畫過程的相對速度,比如動畫可能在啟動階段逐漸加速,而在結束階段逐漸減速,或者整個過程都保持相同的速度;

setanimationrepeatcount:方法來指定動畫的重複次數;

注意:預設狀態下,所有支援動畫的屬性在動畫塊中發生的變化都會形成動畫,如果不想讓動畫塊中發生的某變化產生動畫效果,可以通過setanimationenabled:方法來暫時禁止動畫,在完成修改後才重新啟用動畫。

3.屬性動畫的使用

方法一、[uiview  beginanimation:nil context:nil];

[uiview  setanimationduration:2.0];//2秒

...//繼續對動畫進行一系列的設定

...//這裡寫上改變後的屬性變化值

[uiview  commitanimations];

方法二、[uiview  animatewithduration:2.0  animations:^];

二、uiview的常用方法

當呼叫addsubview的時候,會對其進行保留,理解為retain乙個物件就可以,當呼叫removefromsuperview的時候,會釋放,也就是release。

基本的新增和刪除子檢視:

addsubview:新增子檢視

insertsubview:atindex:檢視插入到指定索引位置

insertsubview:abovesubview:將檢視插入到指定檢視之上

insertsubview:belowsubview:將檢視插入到指定檢視之下

bringsubviewtofront:把檢視移動到最頂層

sendsubviewtoback:把檢視移動到最底層

exchangesubviewatindex:withsubviewatindex:把兩個索引對應的檢視調換位置

removefromsuperview:把檢視從父檢視中移除

ios UIView常用動畫效果

一 呼叫 1 2 3 4 5 6 if m viewscenario.superview nil 展示,由小變大 1 2 3 4 5 6 7 8 9 10 11 12 13 void zoomin uiview view andanimationduration float duration and...

IOS UIView 之屬性篇

本文 做的放大的時候 想加渲染的,但是uiview的一些渲染屬性是7之後才有的,所以現在來了解一下uiview的屬性吧 uiview 之屬性篇 properties property nonatomic cgfloat alpha 設定檢視的透明度 透明度的設定從最小0.0到1.0 1.0為完全不透...

IOS UIView 之屬性篇

uiview 之屬性篇 properties property nonatomic cgfloat alpha 設定檢視的透明度 透明度的設定從最小0.0到1.0 1.0為完全不透明,其中這個屬性只影響當前檢視,並不會影響其子檢視 property nonatomic,getter isopaque...