首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >限制UIButton沿UIBezierPath路径的移动

问限制UIButton沿UIBezierPath路径的移动
EN

Stack Overflow用户
提问于 2013-11-19 08:55:48
回答 2查看 275关注 0票数 0

我有一个圆形UIBezierPath。我使用路径在我的视图上画一个圆圈,创建一个24小时钟的轮廓。我有一个UIButton,它的位置取决于当前的时间。这个按钮就像一只时针。我希望用户能够沿着循环路径移动UIButton。我称之为“访问未来/过去”功能。如何将按钮移动限制在我的路径上?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-19 10:18:59

在视图中重写touchesBegan:和touchesMoved:方法

代码语言:javascript
复制
- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event 
{
   if([[event touchesForView:button] count])
   {
       //User is trying to move the button set a variable to indicate this.
   }
}



- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event 
{
    CGPoint *point = [[event anyObject] locationInView:self];

    /*Compare x and y coordinates with the centre property of the button 
      If x or y are greater set center of button to next point in circle or previous
      point if any of them are lesser.*/
}

注意,在尝试之前,您必须将圆圈中的所有点保存在数组中,或者必须通过知道圆周的半径来计算圆周上的点。

票数 1
EN

Stack Overflow用户

发布于 2013-11-19 09:58:58

最简单的方法是在touchesMoved中,您可以通过以下方法检查忽略不在圆圈视图中的触摸:

代码语言:javascript
复制
CGPoint point = [touch locationInView:circleView];

if (![circleView pointInside:point withEvent:event]) {
     return;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20067060

复制
相关文章

相似问题

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