IOS : ScratchView Xcode 5

144 Views Asked by At

I would like someone to help me, I use this Scratch View https://github.com/SebastienThiebaud/STScratchView in a scratch app and it works very well, but I'm stuck on the way in which I can determine that the view was completly scratched.

I would like a popup fires when the entire view was scraped.

here is the code of viewDidLoad and the function touchesMoved :

  #import "STScratchView.h"
  int j=0;

 - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

// Set up the STScratchView

[_scratchView1 setSizeBrush:70.0];
UIImageView *ball = [[UIImageView alloc] initWithFrame:CGRectMake(8, 321, 129, 133)];
[ball setImage:[UIImage imageNamed:@"ball.png"]];
[_scratchView1 setHideView:ball];

[_scratchView2 setSizeBrush:70.0];
UIImageView *ball1 = [[UIImageView alloc] initWithFrame:CGRectMake(96, 286, 129, 133)];
[ball1 setImage:[UIImage imageNamed:@"ball.png"]];
[_scratchView2 setHideView:ball1];

[_scratchView3 setSizeBrush:70.0];
UIImageView *ball3 = [[UIImageView alloc] initWithFrame:CGRectMake(181, 319, 129, 133)];
[ball3 setImage:[UIImage imageNamed:@"ball.png"]];
[_scratchView3 setHideView:ball3];

int i = arc4random() % 100;
int gangant = 1;
NSString *prix = [NSString stringWithFormat:@"%d",i];

if( gangant == 1)
{
    [_dollarsAmount1 setText:[NSString stringWithFormat:@"$ %d", i]];
    [_dollarsAmount2 setText:[NSString stringWithFormat:@"$ %d", i]];
    [_dollarsAmount3 setText:[NSString stringWithFormat:@"$ %d", i]];
    [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"gangant"];
    [[NSUserDefaults standardUserDefaults] setObject:prix forKey:@"prix"];

}
else
{
    [_dollarsAmount1 setText:[NSString stringWithFormat:@"$ 0"]];
    [_dollarsAmount2 setText:[NSString stringWithFormat:@"$ 0"]];
    [_dollarsAmount3 setText:[NSString stringWithFormat:@"$ 0"]];
    [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"gangant"];
}

 }



 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
  [super touchesMoved:touches withEvent:event];

j = j+1;

if( j == 250 )
{

    NSString *gangant = [[NSUserDefaults standardUserDefaults] stringForKey:@"gangant"];
    NSString *price= [[NSUserDefaults standardUserDefaults] stringForKey:@"price"];

    if([gangant compare:@"YES"] == NSOrderedSame)
    {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Congratulations "
                                                          message:[NSString stringWithFormat:@"You have won %@ $", price]
                                                         delegate:self
                                                cancelButtonTitle:nil
                                                otherButtonTitles:@"Share", @"Continue", nil];

        message.transform = CGAffineTransformTranslate( message.transform, 0.0, 100.0 );
        [message show];

    }else if([gangant compare:@"NO"] == NSOrderedSame)
    {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"You Lost!"
                                                          message:nil
                                                         delegate:self
                                                cancelButtonTitle:nil
                                                otherButtonTitles:@"Share",@"Continue", nil];
        [message show];
    }
     j=0;




}


}

I did not find a way to determine if the view has been completely scratched or not, the solution that I put is not functional, I put a variable j and I incremented once I touch the scratch view and I test if j == 250.

1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution here , i can do it by calculate the percentage of black/white pixels for the mask.