将图像从UIPopoverController拖放到UIViewController

时间:2012-01-30 15:15:29

标签: ios drag-and-drop uipopovercontroller uigesturerecognizer

我在ViewController中显示了一个UIPopoverController,我想将一个图像从popover拖到ViewController。

我知道要做到这一点,我需要使用UIGestureRecognizer,但我不知道如何。我可以在弹出窗口周围移动图像,但我无法将其拖放到ViewController。

我的代码:

-(void)viewDidLoad
{
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
    [panGesture setMinimumNumberOfTouches:1];
    [panGesture setMaximumNumberOfTouches:1];
    [self.view addGestureRecognizer:panGesture];    
}

- (void)moveImage:(UIPanGestureRecognizer *)recognizer 
{
    CGPoint newCenter = [recognizer translationInView:self.view];

    if([recognizer state] == UIGestureRecognizerStateBegan) {

        beginX = ball.center.x; 
        beginY = ball.center.y;
    }

    newCenter = CGPointMake(beginX + newCenter.x, beginY + newCenter.y);

    [ball setCenter:newCenter];
}

0 个答案:

没有答案