gpt4 book ai didi

iphone - 不让 UIButton 拖到 Circle 外

转载 作者:行者123 更新时间:2023-11-28 22:37:01 31 4
gpt4 key购买 nike

我是 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com