2014-09-25 35 views
-1

我希望有人來幫助我,我在一個臨時應用程序中使用這個Scratch View https://github.com/SebastienThiebaud/STScratchView,它工作得很好,但我堅持我可以確定視圖完整的方式劃傷。IOS:ScratchView Xcode 5

我希望在整個視圖被刮時彈出一個窗口。

這裏是viewDidLoad中的代碼和功能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; 




} 


} 

我沒有找到一個方法來確定是否認爲已經完全劃傷或不是,那我就把解決方案不起作用,我把一個變量j,我增加了一次,我觸摸了劃痕視圖,我測試如果j == 250.

+0

你可以發佈你到目前爲止所嘗試過的嗎? – SiKing 2014-09-25 18:31:56

+0

@SiKing我發佈了代碼,謝謝你的幫助 – devlogi 2014-09-25 21:12:32

回答

1

我找到了解決方案here,我可以通過計算掩模的黑色/白色像素的百分比。