首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITouch / UIEvent -推迟活动?

UITouch / UIEvent -推迟活动?
EN

Stack Overflow用户
提问于 2015-04-20 16:52:52
回答 1查看 192关注 0票数 0

有任何方法来延迟这个touchBegan函数的事件吗?

代码语言:javascript
复制
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *followTouch = [[event allTouches] anyObject];

bull.center = [followTouch locationInView:followTouch.view];}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-26 23:24:11

下面是一个例子。它在触觉移动后的半秒钟内使正方形的运动活跃起来:

代码语言:javascript
复制
-(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];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29753841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档