我正在使用 touchesMoved 方法让图像沿着屏幕底部“跟随”某人的手指。所以图像将跟随手指的 x 位置,但它忽略 y 位置并保持垂直固定在底部(但不是水平固定)。有什么方法可以实现吗?
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// create basket image that will be shown on the screen
basketView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"bucket.png"]];
basketView.frame = CGRectMake(130.0, 412.0, 50.0, 50.0);
[self.view addSubview:basketView];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// get current touch location
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint point = [touch locationInView:self.view];
// update location of the image
basketView.center = point;
}