自动布局
#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讲义里的 动画部分