-1
我想創建並看到一個uiimageview,當我點擊屏幕。 在我擡起手指之前,我想在屏幕周圍移動uiimageview,並且只在手指離開時才移動圖像。繼承人我做了什麼:UITapGestureRecognizer和UIPanGestureRecognizer
- (IBAction)tap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self.view];
UIImageView *circle = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, 50, 50)];
circle.userInteractionEnabled = YES;
[circle setImage:[UIImage imageNamed:@"monkey_1.png"]];
[self.view addSubview:circle];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:circle action:nil];
[recognizer requireGestureRecognizerToFail:pan];
CGPoint translation = [pan translationInView:circle];
pan.view.center = CGPointMake(pan.view.center.x + translation.x, pan.view.center.y + translation.y);
[pan setTranslation:CGPointMake(0, 0) inView:self.view];
}
這對於單個手勢可能會更容易。做一個長按手勢,並在它的動作檢測狀態。一開始你會顯示圖像,改變你會移動圖像,然後清理結束。 – farski