173,动画方法

来源:互联网 发布:sql server decimal 编辑:程序博客网 时间:2024/06/11 22:20


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    UIButton *btn = [[UIButtonalloc]initWithFrame:CGRectMake(20,20,100, 50)];

    btn.backgroundColor = [UIColorgrayColor];

    [btn setTitle:@"显示弹框"forState:UIControlStateNormal];

    [btn setTitleColor:[UIColorredColor]forState:UIControlStateNormal];

    [btn addTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:btn];

}


-(void)click:(UIButton *)button{

    /**

     * 只要修改对象的属性,就可以使用动画方法实现动画 —— frameboundsalpha

     *第一种动画方法:首尾式动画

     */

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:1];

    /**

     *  此处放属性变化代码!

     */

    [UIViewcommitAnimations];

    

    

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(100,150,100, 40)];

    label.text = @"下载成功!";

    /**

     *  colorWithWhite0,就是黑色,而为1,就是白色,alpha为透明度

     */

    label.backgroundColor = [UIColorcolorWithWhite:0alpha:0.1];

    label.textAlignment =NSTextAlignmentCenter;

    label.textColor = [UIColorredColor];

    [self.viewaddSubview:label];

    

    /**

     *第二种动画方法:该种方法最为常用,建议使用

     */

    label.alpha = 0;

    [UIViewanimateWithDuration:1animations:^{

        label.alpha = 1;

    } completion:^(BOOL finished) {

        

        [UIViewanimateWithDuration:1animations:^{

            label.alpha = 0;

        } completion:^(BOOL finished) {

            //将控件从storyboard中移除

            [label removeFromSuperview];

        }];

    }];


}


@end

0 0