iphone - 不让 UIButton 拖到 Circle 外

标签 iphone ios uibutton drag

我是 ios 新手。

我有一个 View ,其中我使用 Quarts 核心绘制了一个圆圈。

我在该圆圈中放置了一个 UIButton,并赋予了拖放该按钮的功能。

现在我想要限制按钮不能被拖出那个圆圈区域。

Button的TouchDragOutSide事件为

- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev
{
    if([viewCanvas pointInside:[[[ev allTouches] anyObject] locationInView:viewCanvas ] withEvent:ev])
        c.center = [[[ev allTouches] anyObject] locationInView:viewCanvas ];

}

此时不能将按钮拖出矩形 View 区域的一侧。

感谢帮助

最佳答案

试试这个..

if([viewCanvas pointInside:[[[ev allTouches] anyObject] locationInView:viewCanvas ] withEvent:ev])
{
UITouch *touch = [[ev touchesForView:c] anyObject];

CGPoint location = [touch locationInView:c];

if((location.x<(viewCanvas.frame.origin.x+viewCanvas.frame.size.width))&&(location.y<(viewCanvas.frame.origin.y+viewCanvas.frame.size.height)))
{
  c.center = [[[ev allTouches] anyObject] locationInView:viewCanvas ];

}
}

关于iphone - 不让 UIButton 拖到 Circle 外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635212/

相关文章:

iphone - 如何在 iPhone 上进行地理编码(不是反向地理编码)?

ios - 仅执行一次旋转(CGAffineTransformMakeRotation)

iphone - 如何将数组数据传递给另一个方法

iphone - 苹果会批准具有PDF和音频文件的应用程序吗?

iPhone,如何从照片库中读取一张图像作为 NSData?

ios纵向和横向模式

ios - 如何在我的 LaunchStoryboard 中显示 CFBundleShortVersionString?

调用了 iOS didReceiveRemoteNotification,但未清除通知下拉列表

ios - UIButton 上的 UIControl.State.Highlighted 图像仅在第一次触摸事件后有效

ios - UIButton 从四面八方填充图像