如何检测手指在屏幕上时出现的触摸?

时间:2014-05-04 10:09:01

标签: ios uiview touchesbegan touchesmoved

例如:我有UIView并且我检测到长按 - 然后出现新的UIView。它现在需要整个屏幕。我仍然在屏幕上放下手指 - 我可以移动手指,但我无法向上移动,因为我的新UIView将会消失。所以现在我必须检测我的新UIView上的触摸,但是没有触及开关和touchesMoved被调用。有没有办法解决这个问题?

我新UIView的代码:

#import "Menu.h"

@implementation Menu
{

  //  int x;
  // int y;
  UIGestureRecognizer *longPressGesture;

}



- (id)initWithFrame:(CGRect)frame
{
  NSLog(@"initWithFrame");
self = [super initWithFrame:frame];
if (self) {
    self.backgroundColor = [UIColor orangeColor];
    self.userInteractionEnabled = YES;
    [self setMultipleTouchEnabled:YES];
    [self setIsAccessibilityElement:YES];
   longPressGesture = [[UIGestureRecognizer alloc]
                       initWithTarget:self
                      action:@selector(longPressBegan:)];

   [self addGestureRecognizer:longPressGesture];

  }
return self;
}


-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
   NSLog(@"TOUCHES BEGAN");
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
  NSLog(@"TOUCHES MOVED");
}

-(void)longPressBegan:(UIGestureRecognizer *)recognizer
 {
   NSLog(@"LONG PRESS");
 }

这些方法(touchesBegan,touchesMoved,longPressBegan)都没有被调用。

0 个答案:

没有答案