UITouch / UIEvent - 延迟事件?
UITouch / UIEvent - delaying the event?
有没有办法延迟这个touchBegan函数的事件?
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *followTouch = [[event allTouches] anyObject];
bull.center = [followTouch locationInView:followTouch.view];}
这是一个例子。它在触摸移动后半秒动画一个正方形的移动:
-(void)pan:(UIPanGestureRecognizer *)pan {
CGPoint touchLocation = [pan locationInView:self.view];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
self.square.center = touchLocation;
});
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
square.backgroundColor = [UIColor redColor];
self.square = square;
[self.view addSubview:square];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:pan];
}
有没有办法延迟这个touchBegan函数的事件?
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *followTouch = [[event allTouches] anyObject];
bull.center = [followTouch locationInView:followTouch.view];}
这是一个例子。它在触摸移动后半秒动画一个正方形的移动:
-(void)pan:(UIPanGestureRecognizer *)pan {
CGPoint touchLocation = [pan locationInView:self.view];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
self.square.center = touchLocation;
});
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
square.backgroundColor = [UIColor redColor];
self.square = square;
[self.view addSubview:square];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:pan];
}