Block动画

来源:互联网 发布:做电子相册什么软件好 编辑:程序博客网 时间:2024/06/06 14:22

//

//  AppDelegate.m

//  Block动画

//

//  Created by qianfeng on 14-8-27.

//  Copyright (c) 2014xuli. All rights reserved.

//


#import "AppDelegate.h"


@implementation AppDelegate

-(void)dealloc

{

    [self.window release];

    [super dealloc];

}

-(void)createView

{

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

   view1.backgroundColor =[UIColorredColor];

    [self.window addSubview:view1];

    

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

   view2.backgroundColor =[UIColor blueColor];

    [self.window addSubview:view2];

    

    UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(200, 150, 100, 100)];

   view3.backgroundColor =[UIColor purpleColor];

    [self.window addSubview:view3];

    

   //block动画效果

   [UIViewanimateWithDuration:3animations:^

     {

       //block 动画实现的就是animations里面的代码修改要改变的视图的frame

        view1.frame = CGRectMake(270, 300, 100, 100);

        view2.frame = CGRectMake(10, 50,100, 100);

       self.window.backgroundColor = [UIColor grayColor];

    }completion:^(BOOLfinish)//如果上面的动画结束以后还想添加其他语句就在completion:后面添加新的block语句否则为nil

     {

       [UIViewanimateWithDuration:3animations:^

         {

            view1.frame= CGRectMake(100, 100, 100, 100);

            view2.frame= CGRectMake(200, 300, 100, 100);

            self.window.backgroundColor = [UIColor greenColor];

            [view3 setAlpha:0.2];//改变视图的透明度

         }completion:nil];

     }

     ];

    

    

    

    

}

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

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

   // Override point for customization afterapplication launch.

   self.window.backgroundColor = [UIColor yellowColor];

   [selfcreateView];

   [self.windowmakeKeyAndVisible];

   return YES;

}


- (void)applicationWillResignActive:(UIApplication*)application

{

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

   // Use this method to pause ongoingtasks, 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 sharedresources, save user data, invalidate timers, and store enoughapplication state information to restore your application to itscurrent state in case it is terminated later. 

   // If your application supportsbackground execution, this method is called instead ofapplicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication*)application

{

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

}


- (void)applicationDidBecomeActive:(UIApplication*)application

{

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

}


- (void)applicationWillTerminate:(UIApplication*)application

{

   // Called when the application is aboutto terminate. Save data if appropriate. See alsoapplicationDidEnterBackground:.

}


@end


0 0
原创粉丝点击