我正在做一个游戏,我希望心脏看起来像在跳动。我的方法是拥有两张心脏图像。一个比另一个大。我有一个作为UIButton(因为要开始游戏,我想点击心脏以这样做),心脏的另一个较大版本是UIImageView。到目前为止,我已经做到了,所以心脏每秒都在改变大小,但是我希望它更加真实。例如,每一秒钟,它都会变成大心脏并向后移动(但不是立即发生,因此清晰可见)。我怎样才能做到这一点?这是我的代码:
PlayViewController.h
#import <UIKit/UIKit.h>
@interface PlayViewController : UIViewController
{
IBOutlet UIButton *heartButton;
IBOutlet UIImageView *heartBig;
NSTimer *heartBeat;
}
@end
PlayViewController.m
#import "PlayViewController.h"
@interface PlayViewController ()
@end
@implementation PlayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
heartBig.hidden = YES;
heartBeat = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(beatHeart) userInfo:nil repeats:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)beatHeart
{
if(heartBig.hidden == true)
heartBig.hidden = false;
else
heartBig.hidden = true;
}
@end
最佳答案
试试这个脉冲动画:
关于ios - 如何模拟跳动的心脏?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25829638/