IOS UIButton事件

来源:互联网 发布:steam数据 编辑:程序博客网 时间:2024/06/06 21:39
来自:http://blog.163.com/cz_jdton/blog/static/92732504201282543017312/

UIControlEventTouchDown

单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候。

UIControlEventTouchDownRepeat

多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。

UIControlEventTouchDragInside

当一次触摸在控件窗口内拖动时。

UIControlEventTouchDragOutside

当一次触摸在控件窗口之外拖动时。

UIControlEventTouchDragEnter

当一次触摸从控件窗口之外拖动到内部时。

UIControlEventTouchDragExit

当一次触摸从控件窗口内部拖动到外部时。

UIControlEventTouchUpInside

所有在控件之内触摸抬起事件。

UIControlEventTouchUpOutside

所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。

UIControlEventTouchCancel

所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。

UIControlEventTouchChanged

当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。

UIControlEventEditingDidBegin

当文本控件中开始编辑时发送通知。

UIControlEventEditingChanged

当文本控件中的文本被改变时发送通知。

UIControlEventEditingDidEnd

当文本控件中编辑结束时发送通知。

UIControlEventEditingDidOnExit

当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。

UIControlEventAlltouchEvents

通知所有触摸事件。

UIControlEventAllEditingEvents

通知所有关于文本编辑的事件。

UIControlEventAllEvents

通知所有事件。


实例:   

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    // btn.frame = rect_screen;

    btn.frame = CGRectMake(frame.size.width - 20.0f - 30.0f, frame.size.height - 50.0f, 30.0f, 50.0f);

    btn.backgroundColor = [UIColor blueColor];

    

    // UIControlEventTouchDragInside

    // UIControlEventTouchDragOutside

    

    [btn addTarget:self action:@selector(dragInside) forControlEvents:UIControlEventTouchDragInside];

    

    [btn addTarget:self action:@selector(dragOutside) forControlEvents:UIControlEventTouchDragOutside];

    

    // dismissView

    [btn addTarget:self action:@selector(upInside) forControlEvents:UIControlEventTouchUpInside];

    

    [self addSubview:btn];

    

    return self;

}


- (void)dragInside

{

    NSLog(@"dragInside...");

}


- (void)dragOutside

{

    NSLog(@"dragOutside...");

}


- (void)upInside

{

    NSLog(@"upInside...");

}


长按事件

UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeCustom];

    [aBtn setFrame:CGRectMake(401006060)];

    [aBtn setBackgroundImage:[UIImage imageNamed:@"111.png"]forState:UIControlStateNormal];

//button点击事件

    [aBtn addTarget:self action:@selector(btnShort:)forControlEvents:UIControlEventTouchUpInside];

    //button长按事件

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:selfaction:@selector(btnLong:)]; 

    longPress.minimumPressDuration = 0.8; //定义按的时间

    [aBtn addGestureRecognizer:longPress];




-(void)btnLong:(UILongPressGestureRecognizer*)gestureRecognizer{

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {

        NSLog(@"长按事件");

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"消息" message:@"确定删除该模式吗?" delegate:selfcancelButtonTitle:@"取消" otherButtonTitles:@"删除"nil];

        [alert show];

    }

}

0 0
原创粉丝点击