码迷,mamicode.com
首页 > 其他好文 > 详细

CALayer的动画跟一个播放音乐的demo

时间:2015-06-25 17:12:34      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

自动布局

#import "ViewController.h"

#import <AVFoundation/AVFoundation.h>

@interface ViewController ()<AVAudioPlayerDelegate>

@property (weak, nonatomic) IBOutlet UIButton *buttonImg;

 

@end

 

@implementation ViewController

{

    AVAudioPlayer *audioPlayer;

}

- (void)viewDidLoad {

    [super viewDidLoad];

       // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

#pragma - buttonImg -

- (IBAction)buttonImg:(UIButton *)sender

{

    NSLog(@"%@",sender.currentTitle);

    NSURL *mp3URL = [[NSBundle mainBundle]URLForResource:@"111" withExtension:@"mp3"];

    NSLog(@"%ld",[sender.currentTitle compare:@"12"]);

    if([sender.currentTitle compare:@"12"])

    {

        mp3URL =  [[NSBundle mainBundle]URLForResource:@"画情透骨" withExtension:@"mp3"];

           }

    if(![sender.currentTitle compare:@"12"])

    {

        

        mp3URL =  [[NSBundle mainBundle]URLForResource:@"111" withExtension:@"mp3"];

    }

    audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:mp3URL error:nil];

    audioPlayer.delegate = self;

    [audioPlayer play];

    [self scale:sender];

    }

#pragma - scale -

- (void) scale:(UIButton *)sender

{

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];

    anim.values = [NSArray arrayWithObjects:[NSValue valueWithCATransform3D:sender.layer.transform],

                   [NSValue valueWithCATransform3D:CATransform3DScale(sender.layer.transform, 0.82, 0.82, 1)],

                   [NSValue valueWithCATransform3D:CATransform3DScale(sender.layer.transform, 1.5, 1.5, 1)], [NSValue valueWithCATransform3D:sender.layer.transform],nil];

    anim.duration = 0.5;

    anim.removedOnCompletion = YES;

    [sender.layer addAnimation:anim forKey:nil];

 

}

@end

4个动画来自疯狂ios讲义里的  动画部分

CALayer的动画跟一个播放音乐的demo

标签:

原文地址:http://www.cnblogs.com/4Dream/p/4600190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!