2013-10-03 104 views
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]; 
    }]; 

我真的需要在這一個幫助,任何問題只問,我總是在這裏:)

+0

您是否嘗試過創建視圖,設置它的框架,使用塊動畫褪色它,然後淡出出來,將它從超級視圖中刪除? – Wain

+0

下面是一個開始的好地方(而不是在StackOverflow上提出毫無意義的開放式問題):[Quartz 2D Programming Guide](https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/drawingwithquartz2d/Introduction/) Introduction.html) –

+0

你能告訴你正在尋找什麼樣的動畫?用戶點擊的點或形狀,還是用戶平移的路徑? – n00bProgrammer

回答

0

您好,感謝您的幫助,我與有關蘋果類似的發光效果的定製解決方案出籠「顯示有關高亮觸摸」這裏是發光編碼:

-(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"]; 


} 

改進的任何建議是值得歡迎的,到目前爲止,它爲我的作品:)

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; 
}