热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

长按手势不工作

如何解决《长按手势不工作》经验,为你挑选了1个好方法。

当我使用这种方法时,长按手势对我不起作用(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属性设置为您的标签.


推荐阅读
author-avatar
汶汐_782
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有