UIView Animations(storyboard)

IOS4.0之前如果要給一個程序添加動畫流程

.h文件

@interface ViewController : UIViewController
{
    
    __weak IBOutlet UIView *view1;
    
    __weak IBOutlet UIView *view2;
}

- (IBAction)View1Button:(UIButton *)sender;

- (IBAction)View2Button:(UIButton *)sender;

.m文件

// beginAnimations 表示要開始動畫
    [UIView beginAnimations:@"aa" context:@"gg"]; //設置動畫
//以下是動畫內容
    view1.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];  //隨機顏色
    CGFloat x = arc4random_uniform(320);
    CGFloat y = arc4random_uniform(480);
    view1.center = CGPointMake(x,y);  //中心點隨機
    [UIView setAnimationDuration:3]; //動畫時間
    [UIView commitAnimations]; //動畫結束

UIView 分爲2中 一種 屬性動畫{ frame conter等}
第二種 過渡動畫 是系統封裝好的動畫
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1 cache:YES];
需要有一個容器,先把已有的容器刪除掉,在添加進新的視圖
Begin an animation block.
Set the transition on the container view.
Remove the subview from the container view.
Add the new subview to the container view.
Commit the animation block.

發佈了43 篇原創文章 · 獲贊 11 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章