0

を使用してタッチイベントを強調表示しようとしていますがUIGestureRecognizer、これまでのCGPointところユーザーが触れた場所を取得できますが、アニメーションについてあまり知らないため、その特定の領域を強調表示する方法がわかりません。

これまでのコードviewDidLoad:

UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gradientTouchDown:)];

[self addGestureRecognizer:singleFingerTap];

タッチの位置を取得するメソッド:

-(void)gradientTouchDown:(UIGestureRecognizer*)recognizer{
    NSLog(@"tap detected.");
    CGPoint point = [recognizer locationInView:nil];

    NSLog(@"x = %f y = %f", point.x, point.y );

}

調べてみると、上記のコードにビューアニメーションを追加する必要があると思いますが、どうすればタッチを認識できますか? コード:

  [UIView animateWithDuration:0.3f
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^
     {
         [sender setAlpha:0.3f];
     }
                     completion:^(BOOL finished)
     {
         [sender setAlpha:1.0f];
     }];

これについて本当に助けが必要です。質問があれば、いつでもここにいます:)

4

2 に答える 2

1

これは、ボタンのプロジェクトの 1 つでアニメーションを実装する方法です。アニメーションは、ボタンを押すとボタンの周りにグローを配置するだけです (組み込みの株式アプリのグラフ ビューで年ボタンを押したときに表示されるグローと同じです)。

まず、これらのターゲットをボタンに追加します。

[button addTarget:self action:@selector(myButtonPressed:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(myButtonReleased:) forControlEvents:UIControlEventTouchUpInside];

次に、これらのメソッドは次のようになります。

- (void) myButtonPressed:(id) sender
{
    UIButton *button = (UIButton *) sender;
    CABasicAnimation *shadowRadius = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ];
    shadowRadius.delegate = self;
    [shadowRadius setFromValue:[NSNumber numberWithFloat:3.0]];
    [shadowRadius setToValue:[NSNumber numberWithFloat:15.0]];
    [shadowRadius setDuration:0.2f];

    [[button layer] addAnimation:shadowRadius forKey:@"shadowRadius"];

    button.layer.shadowRadius = 15.0f;
}
- (void) myButtonReleased:(id) sender
{
    UIButton *button = (UIButton *) sender;

    CABasicAnimation *shadowRadius = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ];
    shadowRadius.delegate = self;
    [shadowRadius setFromValue:[NSNumber numberWithFloat:15.0]];
    [shadowRadius setToValue:[NSNumber numberWithFloat:3.0]];
    [shadowRadius setDuration:0.2f];
    //shadowRadius.autoreverses = YES;

    [[button layer] addAnimation:shadowRadius forKey:@"shadowRadius"];

    button.layer.shadowRadius = 3.0f;
    button.selected = YES;
}
于 2013-10-03T17:20:05.457 に答える
0

こんにちは、助けてくれてありがとう。Apple の「Shows Touch on Highlight」に関連する同様のグロー効果のカスタム ソリューションを思いつきました。グローのコードは次のとおりです。

-(void)gradientTouchDown:(UIGestureRecognizer*)recognizer{
    NSLog(@"tap detected");
    CGPoint point = [recognizer locationInView:nil];


    NSLog(@"x = %f y = %f", point.x, point.y );


    UIImage* image;
    UIColor *color = [UIColor whiteColor];

    UIGraphicsBeginImageContextWithOptions(recognizer.view.bounds.size, NO, [UIScreen mainScreen].scale); {
        [recognizer.view.layer renderInContext:UIGraphicsGetCurrentContext()];

        UIBezierPath* path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, recognizer.view.bounds.size.width, recognizer.view.bounds.size.height)];

        [color setFill];

        [path fillWithBlendMode:kCGBlendModeSourceAtop alpha:1.0];


        image = UIGraphicsGetImageFromCurrentImageContext();
    } UIGraphicsEndImageContext();

    UIView* glowView = [[UIImageView alloc] initWithImage:image];
    glowView.center = self.center;
    [self.superview insertSubview:glowView aboveSubview:self];

    glowView.alpha = 0;
    glowView.layer.shadowColor = color.CGColor;
    glowView.layer.shadowOffset = CGSizeZero;
    glowView.layer.shadowRadius = 10;
    glowView.layer.shadowOpacity = 1.0;


    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.fromValue = @(0.0f);
    animation.toValue = @(0.6f);
    //animation.repeatCount = 2 ? HUGE_VAL : 0;
    animation.duration = 0.2;
    animation.autoreverses = YES;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [glowView.layer addAnimation:animation forKey:@"pulse"];


}

改善のための提案は大歓迎です。これまでのところ、私にとってはうまくいきます:)

于 2013-10-04T14:31:49.220 に答える