1
votes

I have a view controller that have a label, and I want to perform panning to the right on that label.

So what I did so far is:

*add a pan gesture to the label in the nib file

enter image description here

*created a didPan method:

- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender;

and the implementation:

- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender {

    CGPoint newTranslation = [sender translationInView:self.homeLabel];
    self.homeLabel.transform = CGAffineTransformMakeTranslation(newTranslation.x, 0);

}

and changed the screen edge pan gesture recogniser to right.

I thought it should pan now but its now, what am I doing wrong?

tnx

enter image description here

1
Have you hooked up your gesture recogniser to the IBAction? It doesn't look like it. - Christian Fox
@KristianFox yes i did.. - JohnBigs
If you add a breakpoint to -didPan does the method get called? - Christian Fox
Nope :/ haa , why is that..? - JohnBigs
Did you add the gesture to the UILabel or the UIViewController? - Christian Fox

1 Answers

0
votes

So I had some time to try it out myself.

Here's what the Interface Builder looks like with -didPan IBAction connected.

enter image description here

However that didn't work for me. I did some searching and found this also on StackOverflow.

Possible bug with UIScreenEdgePanGestureRecognizer in Interface Builder

So, I would suggest you try implementing it the old fashion way in code.

Try this:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIScreenEdgePanGestureRecognizer *swipeFromLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
    swipeFromLeft.edges = UIRectEdgeLeft;
    [self.view addGestureRecognizer:swipeFromLeft];

    UIScreenEdgePanGestureRecognizer *swipeFromRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
    swipeFromRight.edges = UIRectEdgeRight;
    [self.view addGestureRecognizer:swipeFromRight];
}