作者:汶汐_782 | 来源:互联网 | 2023-05-26 00:18
当我使用这种方法时,长按手势对我不起作用(void)longpressed:(UILongPressGestureRecognizer *)
.当我长按标签时,不会调用手势.
- (void)viewDidLoad {
[super viewDidLoad];
array =[NSMutableArray arrayWithObjects:@"hello",@"we",@"Are",@"Swift", nil];
int ypoint = 60;
for (int i=0; i<[array count]; i++) {
label=[[UILabel alloc]initWithFrame:CGRectMake(100, ypoint, 300, 200)];
label.backgroundColor =[UIColor clearColor];
label.text =[array objectAtIndex:i];
[label setTag:i];
[self.view addSubview:label];
ypoint = ypoint +70;
}
[label setUserInteractionEnabled:YES];
lOngPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longpressed:)];
longPressGesture.minimumPressDuration = 0.6;
longPressGesture.delegate = self;
[label addGestureRecognizer:longPressGesture];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)longpressed:(UILongPressGestureRecognizer *)gesture{
if (gesture.state == UIGestureRecognizerStateBegan) {
UILabel *myLabel= (UILabel *)gesture.view ;
NSInteger myLabelTag =[myLabel tag];
NSString *nameString=[array objectAtIndex:myLabelTag];
NSLog(@"%@",nameString);
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
Ashish P...
7
将userInteractiOnEnabled= true
属性设置为您的标签.
1> Ashish P...:
将userInteractiOnEnabled= true
属性设置为您的标签.