0
好的,所以我希望有人可以对此有所了解。事情是我有一个应用程序,用户可以在其中与大量图标进行交互,这些图标可以在屏幕上拖动。点击一次在打击垫打开它并点击并保持提出一个警报视图,询问您是否要删除它。我正在使用一个计时器来检查用户是否正在点按并在touchesMoved和touchesEnded事件中使计时器无效。问题是,如果你在pad上快速点击,touchesEnded事件永远不会被触发,因此会出现删除对话框,这会让用户感到困惑。任何想法,为什么这是?快速水龙头不会触发已结束
- (void) startTouchTimer:(float)delay
{
self.touchTimer = [NSTimer scheduledTimerWithTimeInterval:delay target:self selector:@selector(touchHeld:) userInfo:nil repeats:NO];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if (touches.count == 1)
{
for(WishPad *pad in self.view.subviews)
{
if ([touch view] == pad)
{
//Animate Selection
[UIView animateWithDuration:0.03
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
pad.highlight.alpha = 0.5;
}
completion:NULL];
self.touchedPad = pad.padName;
[self startTouchTimer:0.40];
[self.view bringSubviewToFront:pad];
}
}
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.touchTimer invalidate];
UITouch *touch = [[event allTouches] anyObject];
if (touches.count == 1)
{
for(WishPad *pad in self.view.subviews)
{
if ([touch view] == pad)
{
CGPoint location = [touch locationInView:self.view];
pad.center =location;
}
}
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
{
[self.touchTimer invalidate];
UITouch *touch = [[event allTouches] anyObject];
if (touches.count == 1)
{
for(WishPad *pad in self.view.subviews)
{
if ([touch view] == pad)
{
//Animate deselection
[UIView animateWithDuration:0.03
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
pad.highlight.alpha = 0;
}
completion:NULL];
CGPoint location = pad.frame.origin;
NSString *position = NSStringFromCGPoint(location);
iWishAppDelegate *delegate = (iWishAppDelegate *)[[UIApplication sharedApplication] delegate];
for (Wish in [delegate.wishes objectForKey:@"<none>"])
{
if ([position isEqual:Wish.position] && [[(WishPad*)[touch view] padName] isEqualToString:Wish.name])
{
self.goToAddWish = [[AddWish alloc] initWithNibName:@"AddWish" bundle:nil];
self.goToAddWish.editWish=YES;
self.goToAddWish.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:self.goToAddWish animated:YES];
[self.goToAddWish editDetailText:Wish];
[self.goToAddWish release];
}
else if ([pad.padName isEqual:Wish.name])
{
Wish.position = position;
[delegate save];
}
}
}
}
}
}
- (void) touchHeld:(NSTimer*)timer
{
[self.touchTimer invalidate];
NSString *wishToDel = [NSString stringWithFormat:@"Delete %@?", self.touchedPad];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:wishToDel message:@"Do you really want to delete this wish?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];
[alertView show];
[alertView release];
}
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == [alertView cancelButtonIndex])
{
//Lots of deleting from plist and deleting image stuff happening here
}
谢谢,我会试试看。 – Glitch 2010-11-28 11:10:50