I have an old application which has an UIView, a mercury. Whenever a negative or positive vote happens, it should change its state on a benchmark from 0-100, showing the current vote standing. The problem is when I change something else on the screen, for example a text in a label, the position of the mercury is reseted to its original position (which is determined in the .xib file).
It worked perfectly in iOS 7.
@property(nonatomic) IBOutlet UIView *mercury;
-(IBAction)happyBtn:(id)sender
{
self.counter++;
self.positiveVotes++;
if(self.show!=NO){
[self newPosition:YES];
}else{
[self newPosition:NO];
}
}
-(IBAction)peekBtn:(id)sender
{
if(self.peekCounter!=0){
self.peekCounter--;
// * if I comment this out, the mercury's position is reseted
//[self.peekLabel setText:[NSString stringWithFormat:@"Available peeks: %d",self.peekCounter ]];
[self newPosition:YES];
}else{
UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"No more peeks" message:@"No more peeks available" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertV show];
}
}
-(void)newPosition:(BOOL)show
{
CGFloat mod = 100/self.counter;
self.pos = mod *self.positiveVotes;
self.fpos = 400- ((300/100)*self.pos);
NSLog(@"counter:%f, positive:%f, mod:%f pos:%f, fpos:%f",self.counter,self.positiveVotes,mod,self.pos,self.fpos);
CGRect mercurybox = self.mercury.frame;
mercurybox.origin.y = self.fpos;
if(show==YES){
self.mercury.frame = mercurybox;
//self.tipLabel.text = [NSString stringWithFormat:@"%0.1f",self.pos];
}
}
Aucun commentaire:
Enregistrer un commentaire