2013-10-03 3 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

당신이보기를 만들려고 그 프레임을 설정 한 날 : 작동, 그것을 퇴색 한 다음 페이드 아웃 블록 애니메이션을 사용하고 superview에서 제거 하시겠습니까? – 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; 
} 
관련 문제