2012-05-14 24 views

回答

1

正如賈斯汀所說,添加一個自定義UIView在界面生成器(或編程)並將其添加到視圖。讓我們稱之爲touchArea。然後在你的Viewcontroller.m文件,落實

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

方法(取決於你想要做什麼),而在這些事情:

UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 
if (CGRectContainsPoint(touchArea.frame, location)) { 

//code to execute 

} 

實際上,我認爲即使是作爲的CGRect放置在視圖上的實例變量可以工作,但以上是我如何實現它的。

1

假設你正在使用Interface Builder,只需要另一個UIView。調整它的大小,並將其放置在您想要觸摸事件發生的位置。然後,讓自定義視圖可以觸摸活動。在編程上,我個人不知道該怎麼做。