2011-07-30 51 views
0

如何限制触摸到特定区域或UIView如何限制触摸事件到特定区域或UIView?

换句话说,我在视图上有一个UIButton,但它似乎被触摸禁用。

我还应该写出触摸做我想做的事情,但就像我说的,我失去了控制UIButton s。

@Implementation 
... 


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


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
} 


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
} 

我解决我的问题......

(我的错误),我做了定位在它之外的UIButtons较小的UIView。子视图被附加到该UIView。 (我可以看到按钮,但我甚至不能按他们)

解决方案(其中2个工作):

  • UIButtons的addSubview到self.view
  • 或...放大较小的UIView到340 x 480的
+0

你能提供更多的细节吗?你如何处理触摸,你的视图层次是什么? – Vladimir

回答

0

如果您的视图(你定义在那里touchesBegan等)的接触不会转发给响应链(其中有你的按钮)下一个响应者,你可以尝试在所有这些方法中调用[super],即:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
    [super touchesBegan:touches withEvent:event]; 
} 

和其他方法相同。另见讨论here

+0

稍后要注意......谢谢 –