-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
//手指在屏幕上每一次觸摸都會產(chǎn)生一個觸摸事件
//這些事件會保存這個NSSet 類型的 touches里
//我們可以取出這個事件
UITouch * touch = [touches anyObject];
[UIView animateWithDuration:0.3 animations:^{
imageView.center = [touch locationInView:self.window];
}];
NSLog(@"window:%@",touch.window);
NSLog(@"view:%@",touch.view);
NSLog(@"phase:%id",touch.phase);
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesEnded");
//可以在這里不使用任何一個事件,只去寫我們自己的方法
[UIView animateWithDuration:0.3 animations:^{
imageView.center = CGPointMake(160, 300);
}];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//那么,手指只要在屏幕有偏移那么就調(diào)用一次這個方法
NSLog(@"touchesMove");
UITouch * touch = [touches anyObject];
NSLog(@"view:%@",touch.view);
if (touch.view == imageView && touch.phase == UITouchPhaseMoved) {
imageView.center = [touch locationInView:self.window];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
//程序運行過程中,進(jìn)來電話,短信,推送等優(yōu)先級比較高的事件
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者