gpt4 book ai didi

iphone - 三层Pan Gesture Recogniser的困惑

转载 作者:可可西里 更新时间:2023-11-01 03:58:20 24 4
gpt4 key购买 nike

A Sketch of my App's View Hierarchy

在开发应用程序时,我遇到了平移手势识别器过多的问题。我的第一个平移手势识别器位于 RecipeSearchVC 的父级 MainViewController 上。这个手势识别器向左或向右滑动整个 View 。我的第二个平移手势识别器位于 RecipeSearchParametersVC 中,它是页面 View Controller 的父级。第三个平移手势手势识别器被添加到嵌套在由 PageViewController 表示的 View Controller 内的 UIControl Wheel。

我知道这听起来很疯狂,而且可以说这是糟糕的设计。但是,我相信这是有凝聚力的工作就可以了。

当尝试旋转滚轮时,它会旋转一两秒,然后手势被 PageViewController 或 MainViewController 取代。通常是 MainViewController 接管。我可以采用什么技术来清楚地区分这些手势识别器中的每一个?

编辑:

对于我对平移手势识别器的描述含糊不清,我深表歉意。MainViewController 有它自己的 UIPanGestureRecpgniser 以允许它向左或向右移动所有内容。RecipeSearchParametersVC 只有一个 UIPanGestureRecogniser,因为它包含 UIPageViewController。它本身不添加手势识别器,而只是从 pageViewController 中获取它们。UIControl 的手势识别器允许它跟踪它应该经历的旋转。

在接受给出的建议时,我可能会从页面 View Controller 中删除手势并用按钮代替它们。我只是想让它像 iBooks 中的图像(可以滚动以显示更多图像)一样工作,所以我认为它会工作得很好。

UIControl UIPanGestureRecogniser代码

/**
* sent to the control when a touch related to the given event enters the control’s bounds
*
* @param touch uitouch object that represents a touch on the receiving control during tracking
* @param event event object encapsulating the information specific to the user event
*/
- (BOOL)beginTrackingWithTouch:(UITouch *)touch
withEvent:(UIEvent *)event
{
[super beginTrackingWithTouch:touch withEvent:event];

CGPoint touchPoint = [touch locationInView:self];

// filter out touchs too close to centre of wheel
CGFloat magnitudeFromCentre = [self calculateDistanceFromCentre:touchPoint];

if (magnitudeFromCentre < 40) return NO;

// calculate distance from centre
CGFloat deltaX = touchPoint.x - _container.center.x;
CGFloat deltaY = touchPoint.y - _container.center.y;

// calculate the arctangent of the opposite (y axis) over the adjacent (x axis) to get the angle
_deltaAngle = atan2(deltaY, deltaX);

_startTransform = _container.transform;

// selection in limbo so set all sector image's to minimum value by changing current one
[self getSectorByValue:_currentSector].alpha = kMinimumAlpha;

return YES;
}

最佳答案

不幸的是,由于我的 Controller 层次结构的性质,我不得不重新考虑我的应用程序的设计。

带有 UIPanGestureRecogniser 的 MainViewController 保持原样。带有 UIControl 的 UIPageViewController 已移至单独的静态 View Controller 。

这个效果好得多,但还不够理想。 UIPageViewController 窃取了任何水平平移,但是这可能可以通过实现按钮来替代滚动来解决。

UIControl 没有手势识别器,但我覆盖了 beginTrackingWithTouch: 和其他方法来跟踪触摸。

我想答案应该是:如果你将太多的手势分层,那你就错了。

关于iphone - 三层Pan Gesture Recogniser的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16672955/

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