UIView动画【渐入alpha、淡出、移动frame、缩放transform、旋转transform rotation】

#import "AppDelegate.h"

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [base release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    base = [[UIView alloc] initWithFrame:CGRectMake(60, 100, 200, 200)];
    base.backgroundColor = [UIColor redColor];
    [self.window addSubview:base];
    
    /*
    //UIView动画
    //标记动画开始
    [UIView beginAnimations:@"view101" context:@3];
    //设置动画加减速方式
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //以秒为单位设置动画时长
    [UIView setAnimationDuration:2.0];
    //设置代理
    [UIView setAnimationDelegate:self];
    //设置动画结束后回掉的代理方法
//    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    //设置动画的重复次数
    [UIView setAnimationRepeatCount:3];
    //设置动画是否做一次反向执行
    [UIView setAnimationRepeatAutoreverses:YES];
    //视图的变化
    base.alpha = 0;
    //提交动画,标识动画块的结束
    [UIView commitAnimations];
    */
    
    //UIView blocks的动画
    [UIView animateWithDuration:2
                     animations:^{
                         base.alpha = 0;
                     } completion:^(BOOL finished) {
                         NSLog(@"finished");
                     }];
    
    
    UIView *view1 = [[UIView alloc] initWithFrame:base.bounds];
    view1.backgroundColor = [UIColor blueColor];
    [base addSubview:view1];
    [view1 release];
    
    UIView *view2 = [[UIView alloc] initWithFrame:base.bounds];
    view2.backgroundColor = [UIColor purpleColor];
    [base addSubview:view2];
    [view2 release];
    
    //UIImageView动画
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
    imgView.backgroundColor = [UIColor clearColor];
    NSMutableArray *imgs = [NSMutableArray array];
    for (int i = 0; i < 17; i++) {
        NSString *name = [NSString stringWithFormat:@"campFire%02d.gif",i+1];
        UIImage *img = [UIImage imageNamed:name];
        if (img != nil) {
            [imgs addObject:img];
        }
    }
    
    //设置动画数组
    imgView.animationImages = imgs;
    //设置时长
    [imgView setAnimationDuration:0.4];
    //开始动画
    [imgView startAnimating];
    
    [self.window addSubview:imgView];
    [imgView release];
    
    
    
    
    
    return YES;
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSNumber *number = context;
    NSLog(@"%@",number);
    NSLog(@"%@",animationID);
    if ([animationID isEqualToString:@"view101"]) {
        NSLog(@"%@",animationID);
    }
}

//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    //设置动画的过度效果
//    [UIView transitionWithView:base
//                      duration:1
//                       options:UIViewAnimationOptionTransitionCurlDown|UIViewAnimationOptionCurveEaseInOut
//                    animations:^{
//                        [base exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//                       } completion:^(BOOL finished) {
//                           
//                       }];
//}



@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值