【发布时间】:2011-07-13 02:59:47
【问题描述】:
//我需要发送事件槽@selector([move:event]) 提前致谢。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
moveTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(move:) userInfo:nil repeats:YES];
}
//我的移动函数
- (void)move:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (location.x > myImageView.center.x){
[UIView animateWithDuration:0.001 animations:^{
myImageView.center = CGPointMake(myImageView.center.x+5, myImageView.center.y);
}];
}
else if (location.x < myImageView.center.x){
[UIView animateWithDuration:0.001 animations:^{
myImageView.center = CGPointMake(myImageView.center.x-5, myImageView.center.y);
}];
}
if (location.y < myImageView.center.y){
[UIView animateWithDuration:0.001 animations:^{
myImageView.center = CGPointMake(myImageView.center.x, myImageView.center.y-5);
}];
}
else if (location.y > myImageView.center.y){
[UIView animateWithDuration:0.001 animations:^{
myImageView.center = CGPointMake(myImageView.center.x, myImageView.center.y+5);
}];
}
}
【问题讨论】:
标签: xcode events selector nstimer touches