所以我有一个弹奏和弦的吉他应用程序,就像autoharp一样。我创建了下面的UIView类,当用户的手指在字符串上滑动时,将滑动变成一个弹拨。
#import "swipetest.h"
@implementation swipetest
@synthesize eStringButton, aStringButton, dStringButton, gStringButton, bStringButton, ehStringButton;
- (void)viewDidLoad {
[NSThread detachNewThreadSelector:@selector(isolateStrums) toTarget:self withObject:nil]; }
- (void)isolateStrums {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(touchesMoved) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint location = [[touches anyObject] locationInView:self];
UIView *subview = [self hitTest:location withEvent:event];
if ([subview isKindOfClass:[UIButton class]])
{
if(CGRectContainsPoint(eStringButton.frame, location)) {
[eStringButton setHighlighted:YES];
[eStringButton sendActionsForControlEvents:UIControlEventTouchDown];
[NSTimer scheduledTimerWithTimeInterval:strumDelay target:self selector:@selector(ETimer) userInfo:nil repeats:NO];
}
else {
[eStringButton setHighlighted:NO];
}
if(CGRectContainsPoint(ehStringButton.frame, location)) {
[ehStringButton setHighlighted:YES];
[ehStringButton sendActionsForControlEvents:UIControlEventTouchDown];
}
else {
[ehStringButton setHighlighted:NO];
}
if(CGRectContainsPoint(bStringButton.frame, location)) {
[bStringButton setHighlighted:YES];
[bStringButton sendActionsForControlEvents:UIControlEventTouchDown];
}
else {
[bStringButton setHighlighted:NO];
}
if(CGRectContainsPoint(aStringButton.frame, location)) {
[aStringButton sendActionsForControlEvents:UIControlEventTouchDown];
[aStringButton setHighlighted:YES];
}
else {
[aStringButton setHighlighted:NO];
}
if(CGRectContainsPoint(dStringButton.frame, location)) {
[dStringButton setHighlighted:YES];
[dStringButton sendActionsForControlEvents:UIControlEventTouchDown];
}
else {
[dStringButton setHighlighted:NO];
}
if(CGRectContainsPoint(gStringButton.frame, location)) {
[gStringButton setHighlighted:YES];
[gStringButton sendActionsForControlEvents:UIControlEventTouchDown];
}
else {
[gStringButton setHighlighted:NO];
}
}
}
- (void)dealloc {
[eStringButton release];
[aStringButton release];
[bStringButton release];
[gStringButton release];
[dStringButton release];
[ehStringButton release];
[super dealloc];
}
@end
问题在于,即使在正常的速度下,视图也能快速点击“命中”。如何减慢界面响应?我不能使用任何暂停NSthread的命令。有没有办法在收到UIControlEventTouchDown消息之后的一段预定时间内禁用UIButton,比如0.1秒?我应该为每个字符串创建单独的线程并暂停这些线程吗?现在它有点工作,但很容易变成“矩阵”听起来口吃的吉他。不好。
答案 0 :(得分:1)
有没有办法禁用UIButton 在预定的一段时间内 收到后 比如UIControlEventTouchDown消息 持续0.1秒?
当然 - 您可以使用NSTimer更改按钮的.userInteractionEnabled属性。只要您检测到触碰,就将其设置为“NO”,并在设定数量/分数秒后触发定时器将其设置回“YES”。