ios - 限制 UIButton 沿 UIBezierPath 路径的移动

标签 ios objective-c uibezierpath

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

最佳答案

在您的 View 中重写 touchesBegan:touchesMoved: 方法

- (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.*/
}

请注意,在尝试此操作之前,您必须将圆中的所有点保存在一个数组中,否则您将必须通过知道半径来计算圆周上的点。

关于ios - 限制 UIButton 沿 UIBezierPath 路径的移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20067060/

相关文章:

ios - QLPreviewController NavigationBar barTintColor

objective-c - 如何强制发生 “Expression result unused” 警告

iphone - iOS 无法在扩展类中找到方法

swift - Swift 中 UIView 的圆顶角

ios - 以曲线形状剪切贝塞尔曲线路径

ios - 如何使用 UIBezierPath 绘制带有动画的扇形?

ios - SpriteKit 正确的 Assets 大小

iphone - 关于 SQLite3 和更新 iPhone 应用程序的问题

ios - 以编程方式使用矢量图像(例如 UIBarButtonItem)

ios - 模态视图 Controller 关闭时应用程序崩溃