0

少し明るめの 4 つの画像を循環させようとしています。光っているように見せようとしていますが、コードが思ったように機能しているとは思いません。

  -(void)loadRefreshButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    refreshButton = button;
    [button addTarget:self
               action:@selector(refreshButtonPressedResult)
     forControlEvents:UIControlEventTouchDown];    [refreshButton setTitle:@"" forState:UIControlStateNormal];
    refreshButton.frame = CGRectMake(80.0, 370.0, 76, 76);
    [self.view addSubview:refreshButton];
    NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
                                                      target: self
                                                    selector: @selector(toggleButtonImage:)
                                                    userInfo: nil
                                                     repeats: YES];
}


    - (void)toggleButtonImage:(NSTimer*)timer
{


     if(toggle)
        {
        [refreshButton setImage:[UIImage imageNamed:@"button_zero.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_one.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_two.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_three.png"] forState: UIControlStateNormal];
        }
    else
        {
        [refreshButton setImage:[UIImage imageNamed:@"button_three.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_two.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_one.png"] forState: UIControlStateNormal];
        [refreshButton setImage:[UIImage imageNamed:@"button_zero.png"] forState: UIControlStateNormal];
        }
    toggle = !toggle;
}

ありがとうございました!

4

3 に答える 3

1

おそらく、UIViewクラス メソッドanimateWithDurationによって目的の効果が得られるでしょう。それは単純です:

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     refreshButton.alpha = 0.75;
                 }
                 completion:nil];

もちろん、必要な効果が得られるように調整durationしてください。alpha

于 2012-11-20T07:25:53.017 に答える
0

4つの画像は必要ありません。より鮮明な単一の画像を作成でき、次のコードを使用してアニメーションを点滅させることができます。

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [animation setFromValue:[NSNumber numberWithFloat:1.0]];
    [animation setToValue:[NSNumber numberWithFloat:0.3]];
    [animation setDuration:0.8f];
    [animation setTimingFunction:[CAMediaTimingFunction
                                  functionWithName:kCAMediaTimingFunctionLinear]];
    [animation setAutoreverses:YES];
    [animation setRepeatCount:INFINITY];
    [[aButton layer] addAnimation:animation forKey:@"opacity"];
于 2012-11-20T06:57:27.113 に答える
0

このコードを追加するだけです

- (void)toggleButtonImage:(NSTimer*)timer
{
        ///write your code above which define above after at last just add this code..
        CATransition *animation = [CATransition animation];
        [animation setDelegate:self];   
        [animation setType:kCATransitionFade];
        [animation setDuration:0.5];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                      kCAMediaTimingFunctionEaseInEaseOut]];
        [[refreshButton layer] addAnimation:animation forKey:@"transitionViewAnimation"];
}
于 2012-11-20T07:13:36.153 に答える