如何实施";“手指追踪”;像iOS模拟器一样的应用层

如何实施";“手指追踪”;像iOS模拟器一样的应用层,ios,uiview,touch-event,Ios,Uiview,Touch Event,现在我们的应用程序已经发布,我们的培训负责人有一个请求: “该应用程序很酷,但我们需要一种显示手指运动的模式,比如模拟器中手势的显示方式,或者基调中iPad的激光指针模式[这样我们就可以拍摄电影]。” 这是一个应用程序,每个选项卡(4)都使用带XIB的UITabBarController。这是一个非常复杂的应用程序,带有交互手势识别器,我做了一个“第一,不要伤害”的噩梦 我尝试使用以下方案在选项卡控制器上方添加一个简单的“全局UIView”: 我的“PresentationView”尝试: 在我

现在我们的应用程序已经发布,我们的培训负责人有一个请求:

“该应用程序很酷,但我们需要一种显示手指运动的模式,比如模拟器中手势的显示方式,或者基调中iPad的激光指针模式[这样我们就可以拍摄电影]。”

这是一个应用程序,每个选项卡(4)都使用带XIB的UITabBarController。这是一个非常复杂的应用程序,带有交互手势识别器,我做了一个“第一,不要伤害”的噩梦

我尝试使用以下方案在选项卡控制器上方添加一个简单的“全局UIView”:

我的“PresentationView”尝试:

在我的应用程序代理中:

UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
[self setPresentationView:[[PresentationView alloc] initWithFrame: [mainWindow frame]]];
[mainWindow insertSubview:presentationView aboveSubview:mainWindow];
班级:

//  PresentationView.h
#import <UIKit/UIKit.h>

@interface PresentationView : UIView
{
    NSMutableDictionary *touchesInView;
}
@property (nonatomic, retain) NSMutableDictionary *touchesInView;
@end


#import "PresentationView.h"
#import "TouchPoint.h"

@implementation PresentationView
@synthesize touchesInView;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [ self setAlpha:0.1];
        [self setBackgroundColor:[UIColor whiteColor]];

        [self setUserInteractionEnabled:YES];
        [self setMultipleTouchEnabled:YES];
        touchesInView = [[NSMutableDictionary alloc] init];
    }
    return self;
}

- (void) dealloc
{
    [touchesInView release];
    touchesInView = nil;

    [super dealloc];
}

- (void)drawRect:(CGRect)rect
{
    if ([touchesInView count] < 1)
        return;

    CGContextRef context = UIGraphicsGetCurrentContext();
    NSEnumerator *touchEnum = [touchesInView objectEnumerator];
    TouchPoint *nextTouch;
    float rad = 24;

    while (nextTouch = [touchEnum nextObject]) {
        [[ UIColor redColor] set];
        CGContextAddArc(context, nextTouch.current.x, nextTouch.current.y, rad, 0.0, M_PI*2, 1);
        CGContextFillPath(context);
        CGContextStrokePath(context);
    }
}

- (UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    [self setNeedsDisplay];

    return [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] hitTest:point withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for( UITouch *t in touches )
    {
        NSValue *key = [NSValue valueWithPointer:t];
        CGPoint loc = [t locationInView:self];
        TouchPoint *newTouch = [[TouchPoint alloc] init];

        [newTouch setBegan:loc];
        [newTouch setCurrent:loc];
        [newTouch setTapCount:[t tapCount]];

        [touchesInView setObject:newTouch forKey:key];

        [newTouch release];
    }
    [self setNeedsDisplay];

    [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] touchesBegan:touches withEvent:event];
}
// More touch methods- all ignored
//PresentationView.h
#进口
@接口表示视图:UIView
{
NSMutableDictionary*touchesInView;
}
@属性(非原子,保留)NSMutableDictionary*touchesInView;
@结束
#导入“PresentationView.h”
#导入“TouchPoint.h”
@实现表示视图
@综合触觉视觉;
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
[自我设定α:0.1];
[self-setBackgroundColor:[UIColor whiteColor]];
[self-setUserInteractionEnabled:是];
[自设置多点触控:是];
touchesInView=[[NSMutableDictionary alloc]init];
}
回归自我;
}
-(无效)解除锁定
{
[触摸查看发布];
touchesInView=nil;
[super dealoc];
}
-(void)drawRect:(CGRect)rect
{
如果([touchesInView count]<1)
返回;
CGContextRef context=UIGraphicsGetCurrentContext();
N分子*touchEnum=[touchesInView对象枚举器];
接触点*nextTouch;
浮动半径=24;
而(nextTouch=[touchEnum nextObject]){
[[UIColor redColor]集];
CGContextAddArc(上下文,nextTouch.current.x,nextTouch.current.y,rad,0.0,M_PI*2,1);
CGContextFillPath(上下文);
CGContextStrokePath(上下文);
}
}
-(UIView*)hitTest:(CGPoint)point with event:(UIEvent*)event
{
[自我设置需要显示];
返回[UIApplication sharedApplication]keyWindow]子视图]对象索引:0]命中测试:带有事件的点:事件];
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
适用于(UITouch*t in触控)
{
NSValue*键=[NSValue valueWithPointer:t];
CGPoint loc=[t locationInView:self];
接触点*newTouch=[[TouchPoint alloc]init];
[newTouch setBegan:loc];
[新触摸设置电流:loc];
[newTouch setTapCount:[t tapCount]];
[touchesInView setObject:newTouch-forKey:key];
[新触摸释放];
}
[自我设置需要显示];
[UIApplication sharedApplication]keyWindow]子视图]对象索引:0]触摸开始:触摸事件:事件];
}
//更多触摸方法-全部忽略
这种方法很有效-视图位于所有其他视图之上,并且
hitTest:withEvent:
激发,我在
drawRect:
中成功地在命中点绘制了一个红色圆圈

但当我尝试跟踪触摸时,它会崩溃-
触摸开始/移动/结束
不触发。(是的,我已为此全局视图启用了
UserInteractionEnabled
setMultipleTouchEnabled
)。幸运的是,我没有在下面的任何内容上搞砸手势识别-其他视图正在获取事件,并且应用程序在这个全局视图下正常运行


通常我使用IB来构建/定位视图,而不是从头开始在代码中构建它们,所以很可能存在(一个?/几个?)简单的UIView属性,我没有正确设置。。。但我看不见。还是我会因此而陷入麻烦,试图将事件向下转发?

有一个称为FingerTips的好框架可以做到这一点


它也很容易实现,并且只有在有外部显示器的情况下才显示圆圈,因此您需要演示它

有一个很好的框架叫做FingerTips,可以做到这一点


它也很容易实现,并且只有在有外部显示器的情况下才显示圆圈,因此您需要演示它

对于其他将来的参考(ios fingertips的GIS不是非常有用),fingertips框架位于GitHub上。我使用的分支:。这正是我们需要的,比我想出来的任何东西都要早几光年。谢谢不用担心,很高兴我能帮上忙。对于其他将来的参考(ios fingertips的GIS不是很有用),fingertips框架在GitHub上。我使用的分支:。这正是我们需要的,比我想出来的任何东西都要早几光年。谢谢不用担心,很高兴我能帮忙。