UIImageView位置在标签文本更新期间重置

时间:2014-09-27 00:11:19

标签: uiimageview position ios8 xcode6

这里真的很奇怪。

将XCode6与iOS8一起使用

我有一个简单的UIImageView,当我点击它时会在屏幕上移动。没问题 - 效果很好。

我只是有一个简单的方法来更新特定的标签......基于一个名为StrikesLeft的int。

这是我的updateLabels方法:

-(void)displayLabels{
//update strikes label
strikesLeftDisplay = [NSString stringWithFormat: @"%d", strikesLeft];
lblStrikes.text=strikesLeftDisplay;
} 

这是一个奇怪的问题:

如果我实际上没有更新标签,它就没有问题......但是一旦标签在viewController上更新,UIImageView就会因某种原因重新回到起始位置。

UIImageView更改位置在NSTimer中,如下所示:

runningMovement=[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(startRunning) userInfo:nil repeats:YES];

*编辑 - 这是我的startRunning方法:

- (void)startRunning{
if(livesLeft==0){[self endGame];}

manX=man.frame.origin.x;
manY=man.frame.origin.y;

if([direction isEqualToString:@"left"] && touchX < (manX+20)){
    man.center=CGPointMake(man.center.x - runningSpeed,man.center.y);
}else if([direction isEqualToString:@"right"] && touchX > (manX+22)){
    man.center=CGPointMake(man.center.x + runningSpeed,man.center.y);
}
else{
    direction=@"0";
}




//animate runner
if ([direction isEqualToString:@"right"]){
    if(runnerImageNumber==1){UIImage *image=[UIImage imageNamed:@"run1.png"];[man setImage:image];}
    if(runnerImageNumber==2){UIImage *image=[UIImage imageNamed:@"run2.png"];[man setImage:image];}
    if(runnerImageNumber==3){UIImage *image=[UIImage imageNamed:@"run3.png"];[man setImage:image];}
    if(runnerImageNumber==4){UIImage *image=[UIImage imageNamed:@"run4.png"];[man setImage:image];}
    if(runnerImageNumber==5){UIImage *image=[UIImage imageNamed:@"run5.png"];[man setImage:image];}
    if(runnerImageNumber==6){UIImage *image=[UIImage imageNamed:@"run6.png"];[man setImage:image];}
    if(runnerImageNumber==7){UIImage *image=[UIImage imageNamed:@"run7.png"];[man setImage:image];}
    if(runnerImageNumber==8){UIImage *image=[UIImage imageNamed:@"run8.png"];[man setImage:image];}
    if(runnerImageNumber==9){UIImage *image=[UIImage imageNamed:@"run9.png"];[man setImage:image];}
    runnerImageNumber++;
    if(runnerImageNumber==9){runnerImageNumber=1;}
}
if ([direction isEqualToString:@"left"]){
    if(runnerImageNumber==1){UIImage *image=[UIImage imageNamed:@"run10.png"];[man setImage:image];}
    if(runnerImageNumber==2){UIImage *image=[UIImage imageNamed:@"run11.png"];[man setImage:image];}
    if(runnerImageNumber==3){UIImage *image=[UIImage imageNamed:@"run12.png"];[man setImage:image];}
    if(runnerImageNumber==4){UIImage *image=[UIImage imageNamed:@"run13.png"];[man setImage:image];}
    if(runnerImageNumber==5){UIImage *image=[UIImage imageNamed:@"run14.png"];[man setImage:image];}
    if(runnerImageNumber==6){UIImage *image=[UIImage imageNamed:@"run15.png"];[man setImage:image];}
    if(runnerImageNumber==7){UIImage *image=[UIImage imageNamed:@"run16.png"];[man setImage:image];}
    if(runnerImageNumber==8){UIImage *image=[UIImage imageNamed:@"run17.png"];[man setImage:image];}
    if(runnerImageNumber==9){UIImage *image=[UIImage imageNamed:@"run18.png"];[man setImage:image];}
    runnerImageNumber++;
    if(runnerImageNumber==9){runnerImageNumber=1;}
}

}

0 个答案:

没有答案