zoukankan      html  css  js  c++  java
  • UIButton长按事件

     添加长按事件

     1 - (void)viewDidLoad
     2 {
     3     [super viewDidLoad];
     4     // Do any additional setup after loading the view, typically from a nib.
     5     
     6     UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
     7     [aBtn setFrame:CGRectMake(0106060)];
     8     [aBtn setBackgroundColor:[UIColor redColor]];
     9     //button点击事件
    10     [aBtn addTarget:self action:@selector(btnShort) forControlEvents:UIControlEventTouchUpInside];
    11     //button长按事件
    12     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(btnLong:)];
    13     longPress.minimumPressDuration = 0.5//定义按的时间
    14     [aBtn addGestureRecognizer:longPress];
    15     
    16     [self.view addSubview:aBtn];
    17 }
    18 -(void)btnShort
    19 {
    20     NSLog(@"de");
    21 }
    22 -(void)btnLong:(UILongPressGestureRecognizer *)gestureRecognizer{
    23     if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
    24         NSLog(@"长按事件");
    25         UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"消息" message:@"确定删除该模式吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除", nil];
    26         [alert show];
    27     }
    28 }

     更多介绍

    //加个 longPressGesture ,设置如下:
    UILongPressGestureRecognizer *pahGestureRecognizer=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerStateChanged:)];
    pahGestureRecognizer.delegate = self; //指定委托
    pahGestureRecognizer.minimumPressDuration = 0.3//最少按压响应时间
    [scrollView addGestureRecognizer:pahGestureRecognizer];//指定对象为scrollView
    //[pahGestureRecognizer release];
    //实现委托方法:判断手势状态 动作开始、移动变化、结束
    - (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)gestureRecognizer
    {
        switch (gestureRecognizer.state)
        {
            case UIGestureRecognizerStateBegan:
            {
                
            }
            case UIGestureRecognizerStateChanged:
            {
                
            }
            case UIGestureRecognizerStateEnded:
            {
                
            }      
        }
    }

    ---恢复内容开始---

    //如果你打开横向或纵向的滚动条,这里可以设置滚动条的风格
        // UIScrollViewIndicatorStyleDefault, 默认风格
        // UIScrollViewIndicatorStyleBlack,   黑色风格
        // UIScrollViewIndicatorStyleWhite    白色风格
        //[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack]

    ---恢复内容结束---


  • 相关阅读:
    八.正文处理命令及tar命令
    七.用户.群组及权限的深入讨论
    六.用户.群组和权限
    五.目录,文件的浏览,管理和维护
    四.linux 命令及获取帮助
    计算机的基础知识
    三.linux基本的50条命令
    二.Python的基本数据类型及常用功能
    一.编码的转换和基本的算法
    Linux开机自动挂载Windows分区
  • 原文地址:https://www.cnblogs.com/ioschen/p/3311672.html
Copyright © 2011-2022 走看看