UIview 监听

UIView 监听方法  

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

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

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

这里还有几个代理方法

 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;//触摸取消事件

 

- (void)remoteControlReceivedWithEvent:(UIEvent *)event;//注册接受触摸事件的Control 

 以下是在页面实现监听某一区域,并弹出简单的提示。

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

{

UITouch *touch = [touches anyObject];

CGPoint point = [touch  locationInView:self.view];

CGFloat x = point.x;

CGFloat y = point.y;

if (x>=100.0 && x<=200.0 && y>=100.0 &y<=200.0) {

UIAlertView *base = [[UIAlertView alloc] initWithTitle:@"Prompt" message:@"You Click" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];

[base show];

}

}

posted @ 2011-03-11 14:41  autumnyuhe  阅读(574)  评论(0编辑  收藏  举报