不同的触摸国IBAction为

问题描述:

我记得那个黑暗的Xcode的早期版本提供给几个不同的国家对UI元素IBActions连接如当用户按下按钮上的选项,但也没抬手指还没有等我在Xcode 6中看到的只有一个IBAction,例如按下按钮时触发。不同的触摸国IBAction为

我需要几个按钮的IBAction为被调用权当用户触摸按钮,即使没有抬起手指。有什么办法可以做到这一点?

+0

严重的是,@S [R纳亚克,这是值得怀疑,如果需要以特殊的方式进行格式化每个码字。但使用斜体确实没有任何意义。如果您感觉格式化的冲动,请使用代码格式。 – vikingosegundo 2014-09-04 14:18:31

雅只需选择button,并从那里打开connection inspector可以连接根据用途的行动几种方法。

enter image description here

或只需右键单击该按钮并从那里象这样连接

enter image description here

+0

啊哈,我现在看到了什么问题!用UIButton这些事件类型出现。但是通过工具栏或tabbar中的按钮,他们不会。有没有什么办法让工具栏和tabbars中的按钮工作? – BadmintonCat 2014-09-04 12:59:51

+0

@Avalon如果你想要UIBarButtonItem的答案,我可以......但UITabBarItem我不能......只是告诉我。 – Goppinath 2014-09-04 13:16:31

+0

是的,请告诉我它是如何完成的UIBarButtonItem。无论如何,这是又一步。 – BadmintonCat 2014-09-04 13:23:05

我认为你正在寻找的事件是UIEventTouchDown,没有必要对手指的抬起。

这里是UIControlEvents苹果官方文档:

https://developer.apple.com/library/ios/documentation/uikit/reference/uicontrol_class/reference/reference.html#//apple_ref/c/tdef/UIControlEvents

您的请求后differente事件我写你的第二个答案

1)创建UIView子假设MYView这样的事情。

#import "MYView.h" 

@implementation MYView 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 


} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 


} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 


} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 


} 

@end 

2)创建一个UIBarButtonItem(同样的技巧可以适用于UIButton,因为它是直接从UIView继承)这样

UIBarButtonItem *yourBBI = [[UIBarButtonItem alloc] initWithCustomView:[[MYView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]]; 

在这里,我们去...如果你刚刚接触(无需释放你的手指)方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

将被解雇。

希望它会帮助你...

+0

感谢代码示例@Goppinath!但是我想知道,如果我只是在故事板中定义工具栏及其按钮,也就是非代码方式,这种方式是否也可以应用?您可以使用自定义视图类来初始化您的酒吧按​​钮项目,该类别具有触摸状态的处理程序。 显然创建UIAudibleBarButtonItem的子类并添加例如touchesBegan处理程序似乎不会削减它。我想知道为什么它在使用自定义视图类进行初始化时起作用,但在扩展UIAudibleBarButtonItem类时不起作用? – BadmintonCat 2014-09-05 05:50:04