2012-10-25 45 views
2

我有一个iPad项目与UISplitViewController结构:顶部检测透明的UIView倒是

  • RootViewController的
  • DetailviewController

他们两人都是检测自己的类内手势识别器接触。

我想在所有类之上创建一个透明的UIView,以检测只有一个对角滑动(从左下角到右上角)。

因此,当滑动将被检测到时,我将启动一个函数,否则没有附加任何东西,触摸应该在低级视图上传递。

我尝试这两种解决方案:

  • 添加GestureRecognizer这个顶部透明的看法,但这样会隐藏所有接触到较低层次视图(启用用户交互:是ofcourse)。

另一个解决办法是让初始化这样

-(id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
    // Initialization code 
    [self setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.01]]; 
    [self setUserInteractionEnabled:NO]; 
} 

return self; 

}

,并尝试与

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

检测刷卡,但在这一点上的所有接触都没有检测到。

任何人都有一个很好的解决方案?

回答

2

我不会像你提到的那样创建一个透明的UIView。我将在UISplitViewController的视图中添加一个UISwipeGestureRecognizer,这已经是包含所有子视图的视图。你可以有app委派内访问视图:

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 

// attach the swipe gesture to the view that embeds the rootView and the detailView 
UISwipeGestureRecognizer* swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:splitViewController.view action:@selector(swipeUpdated:)]; 
+0

Tnx为快速回答。 –

+0

Tnx @tiguero快速回答。你是对的,但不是所有的IOS版本都支持手势识别器。我发现的是,正确的方法应该是**继承UIWindow并覆盖“ - (void)sendEvent:(UIEvent *)事件'和 - (BOOL)pointInside:(CGPoint)point withEvent: (UIEvent *)事件'。所以我可以调用/或不调用'[super sendEvent:event]'将事件传递给UIViews Hierarchy。你认为这个解决方案的家伙是什么? –

1

难道你不能只是添加一个手势识别器到UISplitViewController的视图?

0

你应该看看Container Controllers。您可以制作自己的SplitViewController,并在检测到滑动的控制器顶部制作第三个视图。自定义容器控制器非常简单,给你很大的灵活性。