2013-06-05 3 views
0

도청 및 드래그 할 때 내 라벨의 테두리 색상을 변경할 수 있고 탭하지 않고 드래그하지 않을 때 테두리 색상이 이전 색상. 팬 및 제스처 인식기를 모두 사용했지만이 코드를 변경하는 코드는 작성하지 않았습니다. 당신은보기 위임 방법을 사용해야합니다탭하여 드래그하여 라벨의 테두리 색상 변경

(void)change:(id)sender { 


    CGRect labelFrame = CGRectMake(230, 240, 300, 30); 

    UILabel *headingLabel = [[UILabel alloc] initWithFrame:labelFrame]; 


    headingLabel.layer.borderColor = [UIColor clearColor].CGColor; 
    headingLabel.layer.borderWidth = 1.0; 
    headingLabel.backgroundColor = [UIColor blackColor]; 
    headingLabel.textColor = [UIColor redColor]; 


    [self.view addSubview:headingLabel]; 
    [headingLabel setUserInteractionEnabled:YES]; 
    headingLabel.text = _textField.text; 



    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panDetected:)]; 
    [self.view addGestureRecognizer:panRecognizer]; 
    [headingLabel addGestureRecognizer:panRecognizer]; 

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapDetected:)]; 
    [self.view addGestureRecognizer:tapRecognizer]; 
    [headingLabel addGestureRecognizer:tapRecognizer];  
} 

(void)panDetected:(UIPanGestureRecognizer *)paramSender{ 
    if (paramSender.state != UIGestureRecognizerStateEnded && 
     paramSender.state != UIGestureRecognizerStateFailed){ 
     CGPoint location = [paramSender locationInView:paramSender.view.superview]; 
     paramSender.view.center = location; 
    } 
} 

(void) tapDetected:(UITapGestureRecognizer *)paramSender { 
    NSUInteger touchCounter = 0; 
    for (touchCounter = 0; 
     touchCounter < paramSender.numberOfTouchesRequired; 
     touchCounter++){ 
     CGPoint touchPoint = 
     [paramSender locationOfTouch:touchCounter 
          inView:paramSender.view]; 
    } 
} 
@end 

답변