UIView Animations(storyboard)

来源:互联网 发布:传奇世界双开辅助软件 编辑:程序博客网 时间:2024/05/01 06:41

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.

0 0