uiview动画



#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];

    self.window.rootViewController = [[UIViewController alloc] init];

    self.window.rootViewController.view.userInteractionEnabled = NO;

    

    //===================================

    //功能:动态的改变视图的frame\形变\颜色和透明度

    //参数1:动画时间

    //参数2:block,用来实现动画结果的代码段

    [UIView animateWithDuration:0.3 animations:^{

       

        //动画结果

        

    }];

    //参数1:动画时间

    //参数2:block,用来实现动画结果的代码段

    //参数3:block,动画结束后需要执行的代码段

    [UIView animateWithDuration:0.3 animations:^{

        //动画结果

    } completion:^(BOOL finished) {

        //finished:是否结束

        //动画结束后执行的代码段

    }];

    

    //=====================================

    //1.创建一个视图

    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

    view.backgroundColor = [UIColor redColor];

    [self.window addSubview:view];

    

    //2.使用动画

    [UIView animateWithDuration:1 animations:^{

        //使用动画效果改变视图的frame

//        view.frame = CGRectMake(100, 500, 100, 100);

        

        //使用动画效果改变视图的背景色

//        view.backgroundColor = [UIColor blackColor];

        

        //使用动画效果改变视图的透明度

        //透明度:0 - 1 (改变父视图的透明度,子视图的透明度会跟着改变;如果只想改变父视图透明,就改变父视图背景颜色的透明度)

//        view.alpha = 0.2;

        

        //使用动画效果改变视图的形变

//        view.transform = CGAffineTransformMakeScale(0.5, 0.5);

        

    }];

    

    

    [UIView animateWithDuration:0.5 animations:^{

        

        //动画结果

        view.transform = CGAffineTransformMakeScale(0.2, 0.2);

        

    } completion:^(BOOL finished) {

       

        //动画结束后移除视图

        NSLog(@"动画结束");

//        [view removeFromSuperview];

        

        //变小的动画结束后,再变回去

        [UIView animateWithDuration:1.5 animations:^{

            

            view.transform = CGAffineTransformMakeScale(1, 1);

        }];

        

        

    }];

    

    NSLog(@"=====");

    

    

    

    

    

    

    

    [self.window makeKeyAndVisible];

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end

//

//  AppDelegate.m

//  05- UIView动画

//

//  Created by 余婷 on 16/4/8.

//  Copyright (c) 2016 余婷. All rights reserved.

//


#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];

    self.window.rootViewController = [[UIViewController alloc] init];

    self.window.rootViewController.view.userInteractionEnabled = NO;

    

    //===================================

    //功能:动态的改变视图的frame\形变\颜色和透明度

    //参数1:动画时间

    //参数2:block,用来实现动画结果的代码段

    [UIView animateWithDuration:0.3 animations:^{

       

        //动画结果

        

    }];

    //参数1:动画时间

    //参数2:block,用来实现动画结果的代码段

    //参数3:block,动画结束后需要执行的代码段

    [UIView animateWithDuration:0.3 animations:^{

        //动画结果

    } completion:^(BOOL finished) {

        //finished:是否结束

        //动画结束后执行的代码段

    }];

    

    //=====================================

    //1.创建一个视图

    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

    view.backgroundColor = [UIColor redColor];

    [self.window addSubview:view];

    

    //2.使用动画

    [UIView animateWithDuration:1 animations:^{

        //使用动画效果改变视图的frame

//        view.frame = CGRectMake(100, 500, 100, 100);

        

        //使用动画效果改变视图的背景色

//        view.backgroundColor = [UIColor blackColor];

        

        //使用动画效果改变视图的透明度

        //透明度:0 - 1 (改变父视图的透明度,子视图的透明度会跟着改变;如果只想改变父视图透明,就改变父视图背景颜色的透明度)

//        view.alpha = 0.2;

        

        //使用动画效果改变视图的形变

//        view.transform = CGAffineTransformMakeScale(0.5, 0.5);

        

    }];

    

    

    [UIView animateWithDuration:0.5 animations:^{

        

        //动画结果

        view.transform = CGAffineTransformMakeScale(0.2, 0.2);

        

    } completion:^(BOOL finished) {

       

        //动画结束后移除视图

        NSLog(@"动画结束");

//        [view removeFromSuperview];

        

        //变小的动画结束后,再变回去

        [UIView animateWithDuration:1.5 animations:^{

            

            view.transform = CGAffineTransformMakeScale(1, 1);

        }];

        

        

    }];

    

    NSLog(@"=====");

    

    

    

    

    

    

    

    [self.window makeKeyAndVisible];

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end


你可能感兴趣的:(uiview动画)