我正在添加两个手指手势来平移UIScrollView
中的自定义3D视图。内部工作不是我做的,仅仅是点的计算以及如何将其绘制到3D视图中。我主要关心的是scrollViewDidZoom
和touchesMoved
函数与我尝试过的方法相冲突。
我尝试计算touches
函数的touchesMoved
,但是它不是很稳定。
我尝试添加UIPanGestureRecognizer
,但与scrollViewDidZoom
冲突。另外,由于我使用的是自定义变量,因此minimumNumberOfTouches
和maximumNumberOfTouches
属性无法正常工作。
我想知道如何添加不会与视图中现有手势冲突的两指手势。
这是用Obj-c编写的,因此是标签,但是欢迎使用Swift回答。
这是代码的摘录。它并没有显示太多,但是基本上我想更好地控制panMode
bool。
- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {
return zoomDummyView;
}
- (void)scrollViewDidZoom:(UIScrollView*)scrollView {
if ([scrollView zoomScale] != 3.0f)
{
//do calculation on zooming
}
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
NSArray* array = [touches allObjects];
//this is what I've tried so far - check count of touches and then use the bool to denote pan mode or not
panMode = array.count > 1 ? true : false
for ( int i = 0; i < [array count]; ++i )
{
//do point calculation
}
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesMoved:touches withEvent:event];
NSArray* array = [touches allObjects];
for ( int i = 0; i < [array count]; ++i )
{
//some point calculation
// simulation of mouse control for the 3D view, as you can see panMode is used to indicate movement between tilt and pan.
input.isLeftButtonDown = !panMode; // for tilt mode
input.isRightButtonDown = false;
input.isMiddleButtonDown = panMode; // for pan mode
input.isSideButton1Down = false;
input.isSideButton2Down = false;
//input simulation
}
}