少见的几种动画效果

  转摘 http://marshal.easymorse.com/archives/3727,自己调试通过的代码

包含

   #import <QuartzCore/QuartzCore.h>


- (void)loadView
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
    UIImage *image=[UIImage imageNamed:@"back0.jpg"];
    
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, 768, 1024, 8, 4 * 768, colorSpace, kCGImageAlphaPremultipliedFirst);
    CGRect rect = CGRectMake(0, 0, 768, 1024);
    CGColorRef fillColor = [[UIColor whiteColor] CGColor];
    CGContextSetFillColor(context, CGColorGetComponents(fillColor));
    
    CGContextMoveToPoint(context, 160.0f, 230.0f);
    CGContextAddLineToPoint(context, 600.0f, 230.0f);
    CGContextAddLineToPoint(context, 600.0f, 100.0f);
    CGContextAddLineToPoint(context, 370.0f, 50.0f);
    CGContextAddLineToPoint(context, 200.0f, 100.0f);
    
    CGContextClosePath(context);
    CGContextClip(context);
    CGContextDrawImage(context, rect, image.CGImage);
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
    CGImageRelease(imageMasked);
    
    UIImageView *backView=[[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [self.view addSubview:backView];
    backView.image=newImage;
    backView.alpha=0.3;
    
    CABasicAnimation *theAnimation1;    //定义动画
    /*
    //左右摇摆
    theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    theAnimation1.fromValue=[NSNumber numberWithFloat:0];
    theAnimation1.toValue=[NSNumber numberWithFloat:-100];
    
    theAnimation1.duration=5.5;//动画持续时间
    theAnimation1.repeatCount=6;//动画重复次数
    theAnimation1.autoreverses=YES;//是否自动重复*/
    
    //旋转
    //theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform"];
    //theAnimation1.toValue = [ NSValue valueWithCATransform3D: CATransform3DMakeRotation(3.1415, 0, 0, 1.0) ];
    
    //缩放
    theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
    theAnimation1.toValue = [NSNumber numberWithDouble:2.5];
    
    
    [backView.layer addAnimation:theAnimation1 forKey:@"animateLayer"];
    
    [newImage release];
    [image release];
}


//按钮从大变小,然后小于正常显示的值,最后恢复正常(就是缩小并有回弹的效果)

 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    button.frame = CGRectMake(20, 100, 200, 30);

    [button setBackgroundColor:[UIColor redColor]];

    [button setTitle:@"FirstViewController" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    

    CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

    [animation setFromValue:[NSNumber numberWithFloat:8]];

    [animation setToValue:[NSNumber numberWithFloat:1]];

    [animation setDuration:5];

    [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.4 :1.3 :1 :1]];

    [button.layer addAnimation:animation forKey:@"bounceAnimation"];

    

    [button release];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值