gpt4 book ai didi

iphone - UIView 触摸问题/问题

转载 作者:行者123 更新时间:2023-11-28 18:44:31 24 4
gpt4 key购买 nike

我的应用程序有点问题。我质疑我的方法。

这是一张图片 Sample App

基本上我需要色轮在透明盒子里旋转。到目前为止,我所拥有的是有效的。我可以拖动色轮,它会旋转。问题是我可以触摸并拖动屏幕上的“任何地方”,它会旋转。我只希望它在“窗口”中旋转。

我基本上添加了一个 UIView 和一个 UIImageView,向 ImageView 添加了 socket ,并在 touchesBegan 和 touchesMoved 中添加了代码来执行动画。轮子是一个完整的圆形图像, subview 被“裁剪”以不显示图像的下半部分。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *thisTouch = [touches anyObject];
delta = [thisTouch locationInView:wheelImage];

float dx = delta.x - wheelImage.center.x;
float dy = delta.y - wheelImage.center.y;
deltaAngle = atan2(dy,dx);

initialTransform = wheelImage.transform;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint pt = [touch locationInView:wheelImage];

float dx = pt.x - wheelImage.center.x;
float dy = pt.y - wheelImage.center.y;
float ang = atan2(dy,dx);

//do the rotation
if (deltaAngle == 0.0) {
deltaAngle = ang;
initialTransform = wheelImage.transform;
}else
{
float angleDif = deltaAngle - ang;
CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif);
wheelImage.transform = newTrans;

currentValue = [self goodDegrees:radiansToDegrees(angleDif)];

}

}

现在...我的问题如下:

  1. 如何让 touchesMoved/Began 仅在 UIView 或 UIImageView 上工作?
  2. 我应该为这个轮子创建一个自定义 UIView,然后将它添加到我的主视图 Controller 吗?2.a.如果我确实创建了一个自定义项,我会遇到同样的触摸问题吗?

最佳答案

您可能需要考虑使用 UISwipeGestureRecognizer 并将其仅添加到您希望识别滑动的 View 中。

关于iphone - UIView 触摸问题/问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458931/

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