首页 > 代码库 > 两个算法,
两个算法,
-(void)lifeViewAnimation
{
static int a = 0;
static BOOL isAdd = NO;
if (a >= 310) {
a = a - 3;
isAdd = NO;
}else if(a == 0){
a = a + 3;
isAdd = YES;
}else if (isAdd)
{
a = a + 3;
}else if (!isAdd)
{
a = a - 3;
}
self.lifeView.frame = CGRectMake(a, self.lifeView.frame.origin.y, self.lifeView.frame.size.width, self.lifeView.frame.size.height);
}
-(void)lifeViewAnimation
{
static int a = 0;
static int beforeA = 0;
static BOOL isPlus = YES;
if(a <= 0) {
isPlus = YES;
}
if(a >= self.view.frame.size.width){
isPlus = NO;
}
beforeA = a;
if (isPlus) {
a = a + 3;
}else{
a = a - 3;
}
if (a == beforeA+3) {
isPlus = YES;
}else{
isPlus = NO;
}
self.lifeView.frame = CGRectMake(a, self.lifeView.frame.origin.y, self.lifeView.frame.size.width, self.lifeView.frame.size.height);
}
两个算法,