为按钮添加效果

时间:2015-03-15 11:09:58

标签: ios objective-c uibutton effect

我有一个类似Hangman的应用程序,区别在于我的应用程序中所选择的字母是有序的,而不是在正确的空间。

-(void)MatchedWordClick:(id)sender{

    UIButton *bt = (UIButton*)sender;
    [bt setTitle:@"" forState:UIControlStateNormal];

    ((UIButton*)[PuzzleView viewWithTag:[[[lstWordToMatch objectAtIndex:nCurrentWord]objectAtIndex:bt.tag-200] integerValue]+100]).hidden = FALSE;
    [[lstWordToMatch objectAtIndex:nCurrentWord]replaceObjectAtIndex:bt.tag-200 withObject:[NSString stringWithFormat:@"%d",-1]];
}


-(void)PuzzleWordClick:(id)sender{

    //AudioServicesPlaySystemSound(sound1);

    UIButton *bt = (UIButton*)sender;
    int nIndex = -1;

    for (int i = 0; i< [[lst_word objectAtIndex:nCurrentWord]length]; i++) {
        UIButton *bt1 = (UIButton*)[self.view viewWithTag:200+i];
        if ([bt1.currentTitle isEqualToString:@""]||bt1.currentTitle == nil) {
            nIndex = i;
            break;
        }
    }
    if (nIndex == -1) {
        NSLog(@"You Macthed Already");
    }else{

        bt.hidden = TRUE;
        [[lstWordToMatch objectAtIndex:nCurrentWord]replaceObjectAtIndex:nIndex withObject:[NSString stringWithFormat:@"%d",bt.tag-100]];
       [((UIButton*)[self.view viewWithTag:200+nIndex])setTitle:bt.titleLabel.text forState:UIControlStateNormal];


    }

    int nCount = 0;
    for (int i = 0; i< [[lst_word objectAtIndex:nCurrentWord]length]; i++) {
        UIButton *bt1 = (UIButton*)[self.view viewWithTag:200+i];
        if ([bt1.currentTitle isEqualToString:@""]||bt1.currentTitle == nil) {
            nCount++;
        }
    }
    if (nCount == 0) {
        NSString *strWord = @"";
        for (int i = 0; i<[[lst_word objectAtIndex:nCurrentWord]length]; i++) {
            UIButton *bt1 = (UIButton*)[self.view viewWithTag:200+i];
            strWord = [NSString stringWithFormat:@"%@%@",strWord,bt1.currentTitle];
        }
        if (![strWord isEqualToString:[lst_word objectAtIndex:nCurrentWord]]) {
            MatchView.userInteractionEnabled = FALSE;
            PuzzleView.userInteractionEnabled = FALSE;
            ErrorAlertView.hidden = FALSE;

           // AudioServicesPlaySystemSound(sound3);


        }else{
            if (nCurrentWord == 0) {

                //// Change Points Value

                if ([[lst_word objectAtIndex:nCurrentWord] length] == 3) {
                    [lblPts setText:[NSString stringWithFormat:@"%d", nPoint+5]];//point value
                }else if ([[lst_word objectAtIndex:nCurrentWord] length] == 4) {
                    [lblPts setText:[NSString stringWithFormat:@"%d", nPoint+10]];
                }else if ([[lst_word objectAtIndex:nCurrentWord] length] >= 5) {
                    [lblPts setText:[NSString stringWithFormat:@"%d", nPoint+15]];

                }
                [self drawSuccessView];
            }else{

                nCurrentWord++;
                [self drawPuzzle:nCurrentWord];
            }
        }
    }
}

此代码正在努力选择一个字母并完成单词,如果我想删除该字母并将其放回原位,它也有效。

当我选择一个字母(来自谜题或来自单词)时,我想要在放回字母或单词时添加像苍蝇一样的效果。 我想要这样的效果,但在这种情况下我不知道怎么做。

int z=40 + random() % 9;
    int w=40+ random() % 9;
    [UIView animateWithDuration:0.5 animations:^{
        self.label13.frame = CGRectMake(-z,-200, 25, 25);
        NSLog(@"aaa");
    }];

0 个答案:

没有答案