다음 코드를 사용하여 내보기를 만듭니다. 내 UILabel
이 스크롤보기 안에 있습니다. 이제는 touchesBegan
내 맞춤 라벨의 클릭 이벤트를 원합니다. 그러나 그것을 얻을 수 없습니다. UILabel이 터치 이벤트에 응답하지 않습니다.
img1 = [[customLabel alloc] initWithFrame:CGRectMake(0,height ,280,10)];//
[img1 setText: [self.answer_set objectAtIndex:i]];
[img1 setTextAlignment:NSTextAlignmentLeft];
[img1 setBackgroundColor:[UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f]];
img1.textColor = [UIColor whiteColor];
img1.lineBreakMode = NSLineBreakByWordWrapping;
img1.numberOfLines = 0;
[img1 sizeToFit];
img1.contentMode = UIViewContentModeScaleToFill;
img1.font = [UIFont fontWithName:@"Arial" size:14.0f] ;
CGFloat labelHeight=[self getStringHeightforLabel:img1];
NSLog(@"LABEL HEIGHT:: %f",labelHeight);
//set frame after getting height
if (labelHeight < 60.0) {
labelHeight = 60.0;
}
[img1 setUserInteractionEnabled:YES];
img1.tag = 5000;
img1.frame=CGRectMake(-5,height,285 + 10,labelHeight + 10);
img1.layer.cornerRadius = 5;
/** Shadow */
CALayer *shadowLayer = [[CALayer alloc] init];
shadowLayer.frame = CGRectMake(-5,height ,img1.frame.size.width,img1.frame.size.height);
shadowLayer.cornerRadius = 10;
shadowLayer.backgroundColor = [UIColor blueColor].CGColor;
shadowLayer.shadowColor = [UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f].CGColor;
shadowLayer.shadowOpacity = 0.6;
shadowLayer.shadowOffset = CGSizeMake(0,0);
shadowLayer.shadowRadius = 5;
[img1.layer setMasksToBounds:YES];
[shadowLayer addSublayer:img1.layer];
[self.ans_labels.layer addSublayer:shadowLayer];
height += img1.frame.size.height + 15;
및 이벤트가 얻을 :
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
NSLog(@"worked",nil);
//[self giveAnswer:touch.view.tag];
if(touch.view.tag == 5000){
// do here
}
}
앞서 이벤트를 얻을 수있었습니다 만, 오늘은. 내가 뭘 잘못하고 있니? 나는 다음과 같은 솔루션으로 결국 마지막이
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
}
라벨에 –
위의 코드를 제거하고 'touchesBegan'메소드를 붙여 넣고 'touchesBegan'이 라벨이 아닌보기임을 알리는 곳에서 터치 이벤트에 tapgesture를 추가 한 경우 라벨에 'tapgesture'를 사용해야합니다. – preetam
I tapgesture를 사용하지 않았습니다. 이 메소드를 사용하고 싶습니다. - (void) touchesBegan : (NSSet *)은 withEvent : (UIEvent *) 이벤트를 건 드리며, – astuter